{"repo":"magnusvk/counter_culture","free":true,"listed":false,"github":"https://github.com/magnusvk/counter_culture","clone":"git clone https://github.com/magnusvk/counter_culture.git","description":"Turbo-charged counter caches for your Rails app.","language":"Ruby","stars":2119,"topics":["counter-cache","rails","ruby","gem","utility-library","activerecord","database"],"license":"MIT","category":"databases-storage","readme_excerpt":"counter culture Turbo-charged counter caches for your Rails app. Huge improvements over the Rails standard counter caches: Updates counter cache when values change, not just when creating and destroying Supports counter caches through multiple levels of relations Supports dynamic column names, making it possible to split up the counter cache for different types of objects Can keep a running count, or a running total Tested against Ruby 3.0, 3.1, 3.2, 3.3 and 4.0 and against the latest patch releases of Rails 6.0, 6.1, 7.0, 7.1, 7.2, 8.0 and 8.1. Please note that -- unlike Rails' built-in counter-caches -- counter culture does not currently change the behavior of the .size method on ActiveRecord associations. If you want to avoid a database query and read the cached value, please use the attribute name containing the counter cache directly. Installation Add counter culture to your Gemfile: Then run bundle install Database Schema You must create the necessary columns for all counter caches. You can use counter culture's generator to create a skeleton migration: Which will generate a migration with code like the following: Note that the column must be and have a default of zero for this gem to work correctly. If you are adding counter caches to existing data, you must add code to manually populate their values to the generated migration. Usage Simple counter-cache Has many association Now, the model will keep an up-to-date counter-cache in the column of the table. Many to many a","default_branch":null,"files":null,"tree":[],"storefront":"/r/magnusvk","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/magnusvk/counter_culture/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}