diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-12-14 13:40:23 +0100 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-12-14 13:42:07 +0100 |
commit | 6c4f6d3773cf5bca992be95e3cc20c238e64a6a0 (patch) | |
tree | 4d3c1f172f2ffff55d2fe21c16874dbbae0f1184 /app/models | |
parent | 1fbda39c8dd8774d13832d5492e800b66ba90d6d (diff) | |
download | gitlab-ce-6c4f6d3773cf5bca992be95e3cc20c238e64a6a0.tar.gz |
Include project in BatchLoader key to prevent returning blobs for the wrong project
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blob.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/app/models/blob.rb b/app/models/blob.rb index 29e762724e3..19ad110db58 100644 --- a/app/models/blob.rb +++ b/app/models/blob.rb @@ -77,9 +77,15 @@ class Blob < SimpleDelegator end def self.lazy(project, commit_id, path) - BatchLoader.for(commit_id: commit_id, path: path).batch do |items, loader| - project.repository.blobs_at(items.map(&:values)).each do |blob| - loader.call({ commit_id: blob.commit_id, path: blob.path }, blob) if blob + 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 end end end |