diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-14 13:50:37 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-12-14 13:50:37 +0000 |
commit | f51141878171c1162818f8fa0133125a5e92d3eb (patch) | |
tree | 98529c5c7211d28d68bf946d7682b98f18ea9058 | |
parent | 78ba3a9ac52b5b247af0c3f970e60423a41ccbf5 (diff) | |
parent | f871027e8ca3e709f5cf8e17315c01e8a0e9dfbb (diff) | |
download | gitlab-ce-f51141878171c1162818f8fa0133125a5e92d3eb.tar.gz |
Merge branch 'dm-batchloader-project' into 'master'
Include project in BatchLoader key to prevent returning blobs for the wrong project
Closes gitlab-ee#4325
See merge request gitlab-org/gitlab-ce!15936
-rw-r--r-- | app/models/blob.rb | 12 | ||||
-rw-r--r-- | spec/support/batch_loader.rb | 5 |
2 files changed, 14 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 diff --git a/spec/support/batch_loader.rb b/spec/support/batch_loader.rb new file mode 100644 index 00000000000..bb790e660a6 --- /dev/null +++ b/spec/support/batch_loader.rb @@ -0,0 +1,5 @@ +RSpec.configure do |config| + config.after do + BatchLoader::Executor.clear_current + end +end |