Forum: Ruby on Rails time-based counter design

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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.
Sure,
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
and
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
count
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
click
count at each click and saving that to the db might slow things down a
bit.

2.  I could count on the basis of a day and reset the counter table at
the
end of each day using a cron job. For example, at 12:00am reset the
counter
table and then start incrementing the counter from 0 at midnight. I'd
like
to do it without a cron job.

Is there a better way to index clicks over a 24 hour period?

Thanks,

Steve O.
http://www.smarkets.net
This topic is locked and can not be replied to.