Caching counters with ActiveRecord's counter caches
Instead of counting the associated records in the database every time the page loads, ActiveRecord’s counter caching feature allows storing the counter and updating it every time an associated object is created or removed.
Tags: ruby, rails, optimization, caching