Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add failing test case for preload_associations_lazily for association defined with scope #42

Conversation

PikachuEXE
Copy link
Contributor

Similar to #40
This is a bug I have no idea how to solve

@coveralls
Copy link

coveralls commented Sep 23, 2020

Pull Request Test Coverage Report for Build 303

  • 11 of 11 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 95.908%

Totals Coverage Status
Change from base Build 298: 0.05%
Covered Lines: 750
Relevant Lines: 782

💛 - Coveralls

@coveralls
Copy link

Pull Request Test Coverage Report for Build 300

  • 5 of 5 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+3.9%) to 99.731%

Totals Coverage Status
Change from base Build 298: 3.9%
Covered Lines: 741
Relevant Lines: 743

💛 - Coveralls

@PikachuEXE
Copy link
Contributor Author

@DmitryTsepelev
Help~
This is more annoying and cannot be workaround

@DmitryTsepelev
Copy link
Owner

Looks like the problem is in the way how #size method works on associations: when association is loaded—it calls #length, otherwise—initiates COUNT(*) DB call. Due to the gem implementation, association is loaded lazily when at least one element of a context is loaded. However, in the spec #size is called before association is loaded, so DB call is initiated (which is a useful behaviour—it can save developer from loading thousands of records to just count them in memory). I've changed a spec to use map (as usual) and added an extra spec, where #size is called after #map—both pass locally. What do you think?

@DmitryTsepelev
Copy link
Owner

BTW replacing #size with #length makes a trick too: when length is called for a first time, Rails goes to the DB, and preloading context loads all other records belonging to it, so the second #length call does not initiate a DB request

@PikachuEXE
Copy link
Contributor Author

I see
Maybe another update for README?

@DmitryTsepelev
Copy link
Owner

Agreed, I'll do my best to do it today, thanks for the heads up! ✊

@PikachuEXE
Copy link
Contributor Author

No need to rush
But I the build seems failing due to some system db query
No idea how to fix

@DmitryTsepelev
Copy link
Owner

Added the readme section and created an issue about extra DB calls

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants