That sounds like a good candidate for Rails.cache. Each time you create a new comment, simply increase the cache counter using the post identifier.
If the cache entry does not exist, run a simple query article.comments.count(depending on your domain model) and re-cache it.
source
share