Skip to content

Commit

Permalink
perf: avoid queries when foreign keys are empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ElMassimo committed Nov 4, 2022
1 parent 9fa32a0 commit 9f4c0c8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/mongoid/includes/association/eager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module Eager
# Internal: Performs eager load and iterates over the preloaded documents
# for the current relation.
def each_loaded_document
@association.load_documents_for(key, keys_from_docs).each do |doc|
foreign_key_values = keys_from_docs

return @association.klass.none if foreign_key_values.empty?

@association.load_documents_for(key, foreign_key_values).each do |doc|
yield doc
end
end
Expand Down

0 comments on commit 9f4c0c8

Please sign in to comment.