简体   繁体   中英

Data in DB in Ruby on Rails

我的朋友问这个问题,我不确定为什么它在我的StackOverflow配置文件中。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM