Let’s say I want to list the items clicked the most the past 24 hours.
I could do a query of a click table and count all the clicks the past 24
hours for each item and sort. After a while the click table will fill up
that count query will become slow.
I can think of 2 options:
Index the click count in a separate table, and increment the click
of each item. At each click, I guess I could do a click count of the
hours and store that click in a counter table. But it seems doing the
count at each click and saving that to the db might slow things down a
I could count on the basis of a day and reset the counter table at
end of each day using a cron job. For example, at 12:00am reset the
table and then start incrementing the counter from 0 at midnight. I’d
to do it without a cron job.
Is there a better way to index clicks over a 24 hour period?