summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Botelho <tiagonbotelho@hotmail.com>2018-09-27 16:04:59 +0100
committerTiago Botelho <tiagonbotelho@hotmail.com>2018-09-28 15:54:51 +0100
commit18d0eebf92edda95a68016e036b851d8553e3cf5 (patch)
treecc92c76a4d29f61a24740e5ab45cd71926677d9c
parentb463b5d0a28dc0b5e3621d56234c8a6d67bf775d (diff)
downloadgitlab-ce-37433-solve-n-1-in-refs-controller-logs-tree.tar.gz
Specs, changelog and GITALY_SERVER_VERSION bump37433-solve-n-1-in-refs-controller-logs-tree
Adds respective repository specs bumps GITALY_SERVER_VERSION Adds Changelog entry
-rw-r--r--GITALY_SERVER_VERSION2
-rw-r--r--Gemfile.rails5.lock4
-rw-r--r--changelogs/unreleased/37433-solve-n-1-in-refs-controller-logs-tree.yml6
-rw-r--r--lib/gitlab/tree_summary.rb4
-rw-r--r--spec/models/repository_spec.rb51
5 files changed, 62 insertions, 5 deletions
diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION
index d9809110a34..3ba7bd5ba83 100644
--- a/GITALY_SERVER_VERSION
+++ b/GITALY_SERVER_VERSION
@@ -1 +1 @@
-=list-last-commits-for-tree
+0.123.0
diff --git a/Gemfile.rails5.lock b/Gemfile.rails5.lock
index ab35a4a399f..a7728af0ebe 100644
--- a/Gemfile.rails5.lock
+++ b/Gemfile.rails5.lock
@@ -279,7 +279,7 @@ GEM
gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0)
rails (>= 3.2.0)
- gitaly-proto (0.117.0)
+ gitaly-proto (0.118.1)
google-protobuf (~> 3.1)
grpc (~> 1.10)
github-linguist (5.3.3)
@@ -1040,7 +1040,7 @@ DEPENDENCIES
gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3)
- gitaly-proto (~> 0.117.0)
+ gitaly-proto (~> 0.118.1)
github-linguist (~> 5.3.3)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-gollum-lib (~> 4.2)
diff --git a/changelogs/unreleased/37433-solve-n-1-in-refs-controller-logs-tree.yml b/changelogs/unreleased/37433-solve-n-1-in-refs-controller-logs-tree.yml
new file mode 100644
index 00000000000..04662a7cfe2
--- /dev/null
+++ b/changelogs/unreleased/37433-solve-n-1-in-refs-controller-logs-tree.yml
@@ -0,0 +1,6 @@
+---
+title: Adds support for Gitaly ListLastCommitsForTree RPC in order to make bulk-fetch
+ of commits more performant
+merge_request: 21921
+author:
+type: performance
diff --git a/lib/gitlab/tree_summary.rb b/lib/gitlab/tree_summary.rb
index de511f25fb7..c2955cd374c 100644
--- a/lib/gitlab/tree_summary.rb
+++ b/lib/gitlab/tree_summary.rb
@@ -83,7 +83,7 @@ module Gitlab
entries.each do |entry|
path_key = entry_path(entry)
- commit = resolve_commit(commits_hsh[path_key])
+ commit = cache_commit(commits_hsh[path_key])
if commit
entry[:commit] = commit
@@ -92,7 +92,7 @@ module Gitlab
end
end
- def resolve_commit(commit)
+ def cache_commit(commit)
return nil unless commit.present?
resolved_commits[commit.id] ||= commit
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 7e1b7c35517..784d17e271e 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -188,6 +188,57 @@ describe Repository do
end
end
+ describe '#list_last_commits_for_tree' do
+ let(:path_to_commit) do
+ {
+ "encoding" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
+ "files" => "570e7b2abdd848b95f2f578043fc23bd6f6fd24d",
+ ".gitignore" => "c1acaa58bbcbc3eafe538cb8274ba387047b69f8",
+ ".gitmodules" => "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9",
+ "CHANGELOG" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
+ "CONTRIBUTING.md" => "6d394385cf567f80a8fd85055db1ab4c5295806f",
+ "Gemfile.zip" => "ae73cb07c9eeaf35924a10f713b364d32b2dd34f",
+ "LICENSE" => "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
+ "MAINTENANCE.md" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
+ "PROCESS.md" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
+ "README.md" => "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863",
+ "VERSION" => "913c66a37b4a45b9769037c55c2d238bd0942d2e",
+ "gitlab-shell" => "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9",
+ "six" => "cfe32cf61b73a0d5e9f13e774abde7ff789b1660"
+ }
+ end
+
+ subject { repository.list_last_commits_for_tree(sample_commit.id, '.').id }
+
+ it 'returns the last commits for every entry in the current path' do
+ result = repository.list_last_commits_for_tree(sample_commit.id, '.')
+
+ result.each do |key, value|
+ result[key] = value.id
+ end
+
+ expect(result).to include(path_to_commit)
+ end
+
+ it 'returns the last commits for every entry in the current path starting from the offset' do
+ result = repository.list_last_commits_for_tree(sample_commit.id, '.', offset: path_to_commit.size - 1)
+
+ expect(result.size).to eq(1)
+ end
+
+ it 'returns a limited number of last commits for every entry in the current path starting from the offset' do
+ result = repository.list_last_commits_for_tree(sample_commit.id, '.', limit: 1)
+
+ expect(result.size).to eq(1)
+ end
+
+ it 'returns an empty hash when offset is out of bounds' do
+ result = repository.list_last_commits_for_tree(sample_commit.id, '.', offset: path_to_commit.size)
+
+ expect(result.size).to eq(0)
+ end
+ end
+
describe '#last_commit_for_path' do
shared_examples 'getting last commit for path' do
subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id }