evilmartians / activerecord-slotted_counters Goto Github PK
View Code? Open in Web Editor NEWActive Record extension providing slotted counters support
License: MIT License
Active Record extension providing slotted counters support
License: MIT License
I added this gem to an existing project hoping to add slotted counters a single troublesome counter column. That implementation worked fine, but when CI ran, all our non-slotted counters started double incrementing.
Expected: Create one associated record which uses non-slotted counter, column increments by 1
What happened: Incremented by 2
I ran the example from the readme:
User.all.with_slotted_counters(:comments).find_each do
_1.comments_count
end
I expected the counts to be preloaded.
It makes a SQL query per row to fetch the count.
I think the issue is that when you define the has_many
association: https://github.com/evilmartians/activerecord-slotted_counters/blob/master/lib/activerecord_slotted_counters/has_slotted_counter.rb#L41
you have a scope. That scope messes with the preload and it has to make a call per row.
Ruby Version:
3.1.2
Framework Version (Rails, whatever):
Rails 7.0.4.2
Activerecord Slotted Counters Version:
0.1.1
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.