diff options
author | Stan Hu <stanhu@gmail.com> | 2018-11-26 13:20:49 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-11-26 13:20:49 +0000 |
commit | 1c1b7a820db168974289039acd9f1f89664b684e (patch) | |
tree | 84c89e3ec02b2b2629064f093f3806d123424bd5 /lib | |
parent | f9c6134b60465a5628c36d396e7f81f04c3ea235 (diff) | |
parent | 4b7e9eaacd3c5ecfb6e8e28a0d36832d1627515a (diff) | |
download | gitlab-ce-1c1b7a820db168974289039acd9f1f89664b684e.tar.gz |
Merge branch 'dm-batch-loader-key' into 'master'
Batch load only data from same repository when lazy object is accessed
See merge request gitlab-org/gitlab-ce!23309
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/diff_refs.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/git/commit.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/git/tag.rb | 14 |
4 files changed, 17 insertions, 35 deletions
diff --git a/lib/gitlab/diff/diff_refs.rb b/lib/gitlab/diff/diff_refs.rb index d4823f60826..dc245377ccc 100644 --- a/lib/gitlab/diff/diff_refs.rb +++ b/lib/gitlab/diff/diff_refs.rb @@ -23,7 +23,7 @@ module Gitlab alias_method :eql?, :== def hash - [base_sha, start_sha, head_sha].hash + [self.class, base_sha, start_sha, head_sha].hash end # There is only one case in which we will have `start_sha` and `head_sha`, diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb index 4f05c4b73a1..5863815ca85 100644 --- a/lib/gitlab/git/commit.rb +++ b/lib/gitlab/git/commit.rb @@ -155,17 +155,9 @@ module Gitlab end def extract_signature_lazily(repository, commit_id) - BatchLoader.for({ repository: repository, commit_id: commit_id }).batch do |items, loader| - items_by_repo = items.group_by { |i| i[:repository] } - - items_by_repo.each do |repo, items| - commit_ids = items.map { |i| i[:commit_id] } - - signatures = batch_signature_extraction(repository, commit_ids) - - signatures.each do |commit_sha, signature_data| - loader.call({ repository: repository, commit_id: commit_sha }, signature_data) - end + BatchLoader.for(commit_id).batch(key: repository) do |commit_ids, loader, args| + batch_signature_extraction(args[:key], commit_ids).each do |commit_id, signature_data| + loader.call(commit_id, signature_data) end end end @@ -175,17 +167,9 @@ module Gitlab end def get_message(repository, commit_id) - BatchLoader.for({ repository: repository, commit_id: commit_id }).batch do |items, loader| - items_by_repo = items.group_by { |i| i[:repository] } - - items_by_repo.each do |repo, items| - commit_ids = items.map { |i| i[:commit_id] } - - messages = get_messages(repository, commit_ids) - - messages.each do |commit_sha, message| - loader.call({ repository: repository, commit_id: commit_sha }, message) - end + BatchLoader.for(commit_id).batch(key: repository) do |commit_ids, loader, args| + get_messages(args[:key], commit_ids).each do |commit_id, message| + loader.call(commit_id, message) end end end diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 067f4026f48..9b48031b2d3 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -80,7 +80,13 @@ module Gitlab end def ==(other) - [storage, relative_path] == [other.storage, other.relative_path] + other.is_a?(self.class) && [storage, relative_path] == [other.storage, other.relative_path] + end + + alias_method :eql?, :== + + def hash + [self.class, storage, relative_path].hash end # This method will be removed when Gitaly reaches v1.1. diff --git a/lib/gitlab/git/tag.rb b/lib/gitlab/git/tag.rb index ade708d0541..23d989ff258 100644 --- a/lib/gitlab/git/tag.rb +++ b/lib/gitlab/git/tag.rb @@ -14,17 +14,9 @@ module Gitlab class << self def get_message(repository, tag_id) - BatchLoader.for({ repository: repository, tag_id: tag_id }).batch do |items, loader| - items_by_repo = items.group_by { |i| i[:repository] } - - items_by_repo.each do |repo, items| - tag_ids = items.map { |i| i[:tag_id] } - - messages = get_messages(repository, tag_ids) - - messages.each do |id, message| - loader.call({ repository: repository, tag_id: id }, message) - end + BatchLoader.for(tag_id).batch(key: repository) do |tag_ids, loader, args| + get_messages(args[:key], tag_ids).each do |tag_id, message| + loader.call(tag_id, message) end end end |