-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22594 from kbrock/precache_rollup_values
Precache rollup values (cherry picked from commit f28d107)
- Loading branch information
Showing
7 changed files
with
130 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module ActiveRecordPreloadScopes | ||
# based upon active record 6.1 | ||
def records_for(ids) | ||
# use our logic if passing in [ActiveRecord::Base] or passing in a loaded Relation/scope | ||
unless (preload_scope.kind_of?(Array) && preload_scope.first.kind_of?(ActiveRecord::Base)) || | ||
preload_scope.try(:loaded?) | ||
return super | ||
end | ||
|
||
preload_scope.each do |record| | ||
owner = owners_by_key[convert_key(record[association_key_name])].first | ||
association = owner.association(reflection.name) | ||
association.set_inverse_instance(record) | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Associations::Preloader::Association.prepend(ActiveRecordPreloadScopes) |
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
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