summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/full_path_resolver.rb
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/resolvers/full_path_resolver.rb
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/resolvers/full_path_resolver.rb')
-rw-r--r--app/graphql/resolvers/full_path_resolver.rb7
1 files changed, 4 insertions, 3 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