File tree 2 files changed +23
-0
lines changed
jit_preloader/active_record/associations/preloader
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 10
10
require 'jit_preloader/active_record/associations/singular_association'
11
11
if Gem ::Version . new ( ActiveRecord ::VERSION ::STRING ) >= Gem ::Version . new ( "7.0.0" )
12
12
require 'jit_preloader/active_record/associations/preloader/ar7_association'
13
+ require 'jit_preloader/active_record/associations/preloader/ar7_branch'
13
14
elsif Gem ::Version . new ( ActiveRecord ::VERSION ::STRING ) >= Gem ::Version . new ( "6.0.0" )
14
15
require 'jit_preloader/active_record/associations/preloader/ar6_association'
15
16
elsif Gem ::Version . new ( ActiveRecord ::VERSION ::STRING ) >= Gem ::Version . new ( "5.2.2" )
Original file line number Diff line number Diff line change
1
+ module JitPreloader
2
+ module PreloaderBranch
3
+ "" "
4
+ ActiveRecord version >= 7.x.x introduced an improvement for preloading associations in batches:
5
+ https://github.com/rails/rails/blob/main/activerecord/lib/active_record/associations/preloader.rb#L121
6
+
7
+ Our existing monkey-patches will ignore associations whose classes are not descendants of
8
+ ActiveRecord::Base (example: https://github.com/clio/jit_preloader/blob/master/lib/jit_preloader/active_record/associations/preloader/ar6_association.rb#L19).
9
+ But this change breaks that behaviour because now Batch is calling `klass.base_class` (a method defined by ActiveRecord::Base)
10
+ before we have a chance to filter out the non-AR classes.
11
+ This patch for AR 7.x makes the Branch class ignore any association loaders that aren't for ActiveRecord::Base subclasses.
12
+ " ""
13
+
14
+ def loaders
15
+ @loaders = super . find_all do |loader |
16
+ loader . klass < ::ActiveRecord ::Base
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ ActiveRecord ::Associations ::Preloader ::Branch . prepend ( JitPreloader ::PreloaderBranch )
You can’t perform that action at this time.
0 commit comments