Skip to content

Commit 09a8509

Browse files
committed
We should only apply the jit_preloader preload to records that require loading
1 parent 848988b commit 09a8509

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/jit_preloader/preloader.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ def jit_preload(associations)
1515
# It is possible that the records array has multiple different classes (think single table inheritance).
1616
# Thus, it is possible that some of the records don't have an association.
1717
records_with_association = records.reject{|r| r.class.reflect_on_association(associations).nil? }
18-
self.class.new(records: records_with_association, associations: associations).call
18+
19+
# Some of the records may already have the association loaded and we should not load them again
20+
records_requiring_loading = records_with_association.select{|r| !r.association(associations).loaded? }
21+
22+
self.class.new(records: records_requiring_loading, associations: associations).call
1923
end
2024

2125
# We do not want the jit_preloader to be dumpable

0 commit comments

Comments
 (0)