summaryrefslogtreecommitdiff
path: root/app/models/blob.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/models/blob.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/models/blob.rb')
-rw-r--r--app/models/blob.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb
index 4f310e70f4f..66a0925c495 100644
--- a/app/models/blob.rb
+++ b/app/models/blob.rb
@@ -80,15 +80,9 @@ class Blob < SimpleDelegator
end
def self.lazy(project, commit_id, path)
- BatchLoader.for({ project: project, commit_id: commit_id, path: path }).batch do |items, loader|
- items_by_project = items.group_by { |i| i[:project] }
-
- items_by_project.each do |project, items|
- items = items.map { |i| i.values_at(:commit_id, :path) }
-
- project.repository.blobs_at(items).each do |blob|
- loader.call({ project: blob.project, commit_id: blob.commit_id, path: blob.path }, blob) if blob
- end
+ BatchLoader.for([commit_id, path]).batch(key: project.repository) do |items, loader, args|
+ args[:key].blobs_at(items).each do |blob|
+ loader.call([blob.commit_id, blob.path], blob) if blob
end
end
end