A Rails gem providing advanced, flexible counter caches that update on value changes and support multi-level relations.
counter_culture is a Ruby on Rails gem that provides turbo-charged counter caches for ActiveRecord models. It solves the limitations of Rails' built-in counter caches by updating counts when record values change, supporting multi-level relations, and offering dynamic column names. This ensures accurate, performant counts without manual SQL queries.
Rails developers building applications with complex model associations who need accurate, high-performance counter caches that update automatically and support advanced use cases like conditional counting or multi-level relationships.
Developers choose counter_culture over Rails' native counter caches for its flexibility, accuracy, and performance. It handles edge cases like value changes, soft deletes, and dynamic conditions, reduces database load through batch updates, and integrates seamlessly with tools like PaperTrail and read replicas.
Turbo-charged counter caches for your Rails app.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Updates counter caches when record values change, not just on creation or destruction, ensuring accuracy in dynamic data environments.
Supports counter caches through multiple levels of ActiveRecord associations, enabling accurate counts in complex model hierarchies.
Aggregates multiple counter updates into single SQL queries with batch processing, reducing database load significantly in bulk operations.
Integrates seamlessly with soft-delete gems like paranoia and discard, maintaining accurate counts even after records are restored.
Does not override ActiveRecord's .size method, so developers must use counter cache attributes directly to avoid unnecessary SQL queries, as explicitly noted in the README.
Setting up dynamic column names requires verbose additional configuration for counter_culture_fix_counts, increasing maintenance overhead and potential for errors.
Can cause database deadlocks in high-concurrency environments, often necessitating the execute_after_commit option and extra gem dependencies like after_commit_action.