Men-Guo / alwayswin

297P Project
0 stars 0 forks source link

Is it better to change thumbenail by trigger #12

Open ShuqingYe1997 opened 3 years ago

ShuqingYe1997 commented 3 years ago

When user update a non-thumbnail figure to thumbnail, or insert a new thumbnail, we need to update the old thumbnail to normal figures and set the new figure as thumbnail.

Currently we are doing this with an extra method in service layer called changeThumbnail(), which requires one select + one update. So the total cost of change thmbnail is:
one insert/update (for new thumbnail) + (one select + one update) (for old thumbnail).

A better solution is using trigger. When a figure is updated to thumbnail, a script will be triggered to de-thumbnailing the old one if there is one. In this way, the whole cost can be reduced to:
one insert/update (for new thumbnail) + one update (for old thumbnail). Let alone all the network delays.

ShuqingYe1997 commented 3 years ago

Done. If you want to enable trigger/function/procedure on AWS RDS, you need to follow these steps: link