Giter Site home page Giter Site logo

activerecord-slotted_counters's People

Contributors

danielwestendorf avatar egor-lukin avatar latyshev avatar palkan avatar prog-supdex avatar yaroslav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

activerecord-slotted_counters's Issues

Non-slotted counters get incremented twice after including this gem

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

N+1 query when using with_slotted_counters()

What did you do?

I ran the example from the readme:

User.all.with_slotted_counters(:comments).find_each do
  _1.comments_count
end

What did you expect to happen?

I expected the counts to be preloaded.

What actually happened?

It makes a SQL query per row to fetch the count.

Additional context

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.

Environment

Ruby Version:

3.1.2

Framework Version (Rails, whatever):

Rails 7.0.4.2

Activerecord Slotted Counters Version:

0.1.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.