0

My friend asked this question I am not sure why it is on my StackOverflow profile.

1 Answer 1

1

Rails supports a technique called counter cache, where you can store the number of messages, comments or anything you want, without executing redundant commands.

There is a railscast that describes it very nicely :

http://railscasts.com/episodes/23-counter-cache-column

If you, however, need to stick to a cron based task, it would be very easy to store the count yourself in a statistics model like :

Statistic.new
Statistic.total_users = User.count 
Statistic.total_comments = Comment.count 
Statistic.save
Sign up to request clarification or add additional context in comments.

1 Comment

you can write a simple rails task to do it for you(more on it railscasts.com/episodes/66-custom-rake-tasks). It would be an entry to the Statistic model, yes. But the code to be executed would be in the Rake Task.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.