Skip to content

Commit

Permalink
Merge pull request #4519 from glasses618/master
Browse files Browse the repository at this point in the history
Improve GraphQL::Dataloader::Source#sync's efficiency
  • Loading branch information
rmosolgo authored Jun 20, 2023
2 parents 978005d + 96edf00 commit d8feb07
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/graphql/dataloader/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def load(key)
result_for(key)
else
@pending_keys << key
sync
sync([key])
result_for(key)
end
end
Expand All @@ -50,7 +50,7 @@ def load_all(keys)
if keys.any? { |k| !@results.key?(k) }
pending_keys = keys.select { |k| !@results.key?(k) }
@pending_keys.concat(pending_keys)
sync
sync(pending_keys)
end

keys.map { |k| result_for(k) }
Expand All @@ -67,8 +67,7 @@ def fetch(keys)
# Wait for a batch, if there's anything to batch.
# Then run the batch and update the cache.
# @return [void]
def sync
pending_keys = @pending_keys.dup
def sync(pending_keys)
@dataloader.yield
iterations = 0
while pending_keys.any? { |k| !@results.key?(k) }
Expand Down

0 comments on commit d8feb07

Please sign in to comment.