You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Similar to #40
This is a bug I have no idea how to solve