summaryrefslogtreecommitdiff
path: root/app/graphql
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2018-11-23 12:26:17 +0100
committerDouwe Maan <douwe@selenight.nl>2018-11-26 11:15:18 +0100
commit5f0e4040ce7d4d0019b3340dd603cc6f67dd036d (patch)
tree76fb16a30e6ea702ecc14164e9b1c4d277ac1920 /app/graphql
parentba9eeea4ee2eb3a43cc3d107a2590a6227af89ed (diff)
downloadgitlab-ce-5f0e4040ce7d4d0019b3340dd603cc6f67dd036d.tar.gz
Batch load only data from same repository when lazy object is accessed
By specifying `key`, we get a different lazy batch loader for each repository, which means that accessing a lazy object from one repository will only result in that repository's objects being fetched, not those of other repositories, saving us some unnecessary Gitaly lookups.
Diffstat (limited to 'app/graphql')
-rw-r--r--app/graphql/resolvers/full_path_resolver.rb7
-rw-r--r--app/graphql/resolvers/merge_request_resolver.rb7
2 files changed, 8 insertions, 6 deletions
diff --git a/app/graphql/resolvers/full_path_resolver.rb b/app/graphql/resolvers/full_path_resolver.rb
index 8d3da33e8d2..0f1a64b6c58 100644
--- a/app/graphql/resolvers/full_path_resolver.rb
+++ b/app/graphql/resolvers/full_path_resolver.rb
@@ -11,10 +11,11 @@ module Resolvers
end
def model_by_full_path(model, full_path)
- BatchLoader.for(full_path).batch(key: "#{model.model_name.param_key}:full_path") do |full_paths, loader|
+ BatchLoader.for(full_path).batch(key: model) do |full_paths, loader, args|
# `with_route` avoids an N+1 calculating full_path
- results = model.where_full_path_in(full_paths).with_route
- results.each { |project| loader.call(project.full_path, project) }
+ args[:key].where_full_path_in(full_paths).with_route.each do |project|
+ loader.call(project.full_path, project)
+ end
end
end
end
diff --git a/app/graphql/resolvers/merge_request_resolver.rb b/app/graphql/resolvers/merge_request_resolver.rb
index b87c95217f7..d047ce9e3a1 100644
--- a/app/graphql/resolvers/merge_request_resolver.rb
+++ b/app/graphql/resolvers/merge_request_resolver.rb
@@ -14,9 +14,10 @@ module Resolvers
def resolve(iid:)
return unless project.present?
- BatchLoader.for(iid.to_s).batch(key: project.id) do |iids, loader|
- results = project.merge_requests.where(iid: iids)
- results.each { |mr| loader.call(mr.iid.to_s, mr) }
+ BatchLoader.for(iid.to_s).batch(key: project) do |iids, loader, args|
+ args[:key].merge_requests.where(iid: iids).each do |mr|
+ loader.call(mr.iid.to_s, mr)
+ end
end
end
# rubocop: enable CodeReuse/ActiveRecord