2 ms·
A way to do this for read heavy applications is to use the separate table to store who has viewed the post, but then use a trigger to update a seen count column
by bastawhiz 4y ago
A way to do this for read heavy applications is to use the separate table to store who has viewed the post, but then use a trigger to update a seen count column. When you write a (unique) row to the table, the trigger counts all the views and updates the posts table. All reads have no extra overhead, only views. You can queue/process the views at your leisure, or pause them altogether as a circuit breaker.
- hardwaresofton 4y agoThis is a great tip, thanks for sharing — reducing read overhead to a minimum and even delaying the processing is fantastic. This would have been great to include as a sort of better assoc table approach
- hyzyla 4y agoI expected to find that solution in article. Or if someone doesn’t like triggers, you can just insert row in associated table, if failed with duplication error, then do nothing, otherwise increase counter.