Forum: Ruby on Rails time-based counter design

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Steve O. (Guest)
on 2006-03-07 00:33
(Received via mailing list)
Hello group,

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:

1. 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
past 24
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

2.  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?


Steve O.
This topic is locked and can not be replied to.