diff options
author | Douwe Maan <douwe@selenight.nl> | 2018-11-23 12:26:17 +0100 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2018-11-26 11:15:18 +0100 |
commit | 5f0e4040ce7d4d0019b3340dd603cc6f67dd036d (patch) | |
tree | 76fb16a30e6ea702ecc14164e9b1c4d277ac1920 /lib | |
parent | ba9eeea4ee2eb3a43cc3d107a2590a6227af89ed (diff) | |
download | gitlab-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 'lib')
-rw-r--r-- | lib/gitlab/git/commit.rb | 28 | ||||
-rw-r--r-- | lib/gitlab/git/tag.rb | 14 |
2 files changed, 9 insertions, 33 deletions
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/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 |