{"repo":"evilmartians/activerecord-slotted_counters","free":true,"listed":false,"github":"https://github.com/evilmartians/activerecord-slotted_counters","clone":"git clone https://github.com/evilmartians/activerecord-slotted_counters.git","description":"Active Record extension providing slotted counters support","language":"Ruby","stars":116,"topics":["activerecord","rails","postgresql"],"license":"MIT","category":"databases-storage","readme_excerpt":"Active Record slotted counters This gem adds slotted counters support to [Active Record counter cache][counter-cache]. Slotted counters help to reduce contention on a single row update in case you have many concurrent operations (like updating a page views counter during traffic spikes). Read more about slotted counters in this post. This project is built by Evil Martians , an American design and engineering consultancy for developer tools, AI, and cybersecurity startups . Installation Add to your project: Requirements - Ruby = 2.7.0 - Rails 6+ Usage First, add and apply the required migration(-s): Then, add the following line to the model to add a slotted counter: Now you can use all the common counter cache APIs as before: Under the hood, a row in the slotted counters table is created associated with the record. NOTE: Reading the current value performs SQL query once: If you want to preload counters for multiple records, you can use a convenient #with slotted counters method: Using counter cache: true on belongs to associations also works as expected. Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/evilmartians/activerecord-slotted counters. Credis This gem is generated via new-gem-generator. License The gem is available as open source under the terms of the MIT License. [counter-cache]: https://api.rubyonrails.org/classes/ActiveRecord/CounterCache/ClassMethods.html","default_branch":null,"files":null,"tree":[],"storefront":"/r/evilmartians","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/evilmartians/activerecord-slotted_counters/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."}