summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-07-25 07:50:35 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-07-25 07:50:35 +0000
commit61bed25a88fca21b9df83dd7f6637ad6c83d5bec (patch)
tree1aef1f41ca830d5497c17c5bc175a29e771d9826
parentd426a53cb11b2a8727163be1cf0ad8035881ab6d (diff)
parentc8ff6b7c73ccf42e70f7fd4675dd7f68d03739c1 (diff)
downloadgitlab-ce-61bed25a88fca21b9df83dd7f6637ad6c83d5bec.tar.gz
Merge branch 'sh-use-wiki-limit-parameter-gitaly' into 'master'
Use limit parameter to retrieve Wikis from Gitaly See merge request gitlab-org/gitlab-ce!20764
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock4
-rw-r--r--Gemfile.rails5.lock4
-rw-r--r--app/controllers/projects/wikis_controller.rb6
-rw-r--r--app/models/project_wiki.rb2
-rw-r--r--changelogs/unreleased/sh-use-wiki-limit-parameter-gitaly.yml5
-rw-r--r--lib/gitlab/git/wiki.rb8
-rw-r--r--lib/gitlab/gitaly_client/wiki_service.rb4
-rw-r--r--spec/controllers/projects/wikis_controller_spec.rb37
-rw-r--r--spec/lib/gitlab/git/wiki_spec.rb25
-rw-r--r--spec/lib/gitlab/gitaly_client/wiki_service_spec.rb22
11 files changed, 105 insertions, 14 deletions
diff --git a/Gemfile b/Gemfile
index 47815f230d3..74e9625d57b 100644
--- a/Gemfile
+++ b/Gemfile
@@ -422,7 +422,7 @@ group :ed25519 do
end
# Gitaly GRPC client
-gem 'gitaly-proto', '~> 0.106.0', require: 'gitaly'
+gem 'gitaly-proto', '~> 0.109.0', require: 'gitaly'
gem 'grpc', '~> 1.11.0'
# Locked until https://github.com/google/protobuf/issues/4210 is closed
diff --git a/Gemfile.lock b/Gemfile.lock
index 22626c0071b..251e3c22397 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -284,7 +284,7 @@ GEM
gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0)
rails (>= 3.2.0)
- gitaly-proto (0.106.0)
+ gitaly-proto (0.109.0)
google-protobuf (~> 3.1)
grpc (~> 1.10)
github-linguist (5.3.3)
@@ -1042,7 +1042,7 @@ DEPENDENCIES
gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3)
- gitaly-proto (~> 0.106.0)
+ gitaly-proto (~> 0.109.0)
github-linguist (~> 5.3.3)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-gollum-lib (~> 4.2)
diff --git a/Gemfile.rails5.lock b/Gemfile.rails5.lock
index 5a0aaf05608..8c14316a67a 100644
--- a/Gemfile.rails5.lock
+++ b/Gemfile.rails5.lock
@@ -287,7 +287,7 @@ GEM
gettext_i18n_rails (>= 0.7.1)
po_to_json (>= 1.0.0)
rails (>= 3.2.0)
- gitaly-proto (0.106.0)
+ gitaly-proto (0.109.0)
google-protobuf (~> 3.1)
grpc (~> 1.10)
github-linguist (5.3.3)
@@ -1052,7 +1052,7 @@ DEPENDENCIES
gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3)
- gitaly-proto (~> 0.106.0)
+ gitaly-proto (~> 0.109.0)
github-linguist (~> 5.3.3)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-gollum-lib (~> 4.2)
diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb
index 9dc0c31be49..b7c656246ef 100644
--- a/app/controllers/projects/wikis_controller.rb
+++ b/app/controllers/projects/wikis_controller.rb
@@ -112,7 +112,7 @@ class Projects::WikisController < Projects::ApplicationController
private
def load_project_wiki
- @project_wiki = ProjectWiki.new(@project, current_user)
+ @project_wiki = load_wiki
# Call #wiki to make sure the Wiki Repo is initialized
@project_wiki.wiki
@@ -128,6 +128,10 @@ class Projects::WikisController < Projects::ApplicationController
false
end
+ def load_wiki
+ ProjectWiki.new(@project, current_user)
+ end
+
def wiki_params
params.require(:wiki).permit(:title, :content, :format, :message, :last_commit_sha)
end
diff --git a/app/models/project_wiki.rb b/app/models/project_wiki.rb
index 3aa56b3983f..f4b3421f04b 100644
--- a/app/models/project_wiki.rb
+++ b/app/models/project_wiki.rb
@@ -82,7 +82,7 @@ class ProjectWiki
# Returns an Array of Gitlab WikiPage instances or an
# empty Array if this Wiki has no pages.
- def pages(limit: nil)
+ def pages(limit: 0)
wiki.pages(limit: limit).map { |page| WikiPage.new(self, page, true) }
end
diff --git a/changelogs/unreleased/sh-use-wiki-limit-parameter-gitaly.yml b/changelogs/unreleased/sh-use-wiki-limit-parameter-gitaly.yml
new file mode 100644
index 00000000000..e8c2e11ad31
--- /dev/null
+++ b/changelogs/unreleased/sh-use-wiki-limit-parameter-gitaly.yml
@@ -0,0 +1,5 @@
+---
+title: Use limit parameter to retrieve Wikis from Gitaly
+merge_request: 20764
+author:
+type: performance
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb
index 8ee46b59830..9d992be66eb 100644
--- a/lib/gitlab/git/wiki.rb
+++ b/lib/gitlab/git/wiki.rb
@@ -44,9 +44,9 @@ module Gitlab
end
end
- def pages(limit: nil)
+ def pages(limit: 0)
@repository.wrapped_gitaly_errors do
- gitaly_get_all_pages
+ gitaly_get_all_pages(limit: limit)
end
end
@@ -158,8 +158,8 @@ module Gitlab
Gitlab::Git::WikiFile.new(wiki_file)
end
- def gitaly_get_all_pages
- gitaly_wiki_client.get_all_pages.map do |wiki_page, version|
+ def gitaly_get_all_pages(limit: 0)
+ gitaly_wiki_client.get_all_pages(limit: limit).map do |wiki_page, version|
Gitlab::Git::WikiPage.new(wiki_page, version)
end
end
diff --git a/lib/gitlab/gitaly_client/wiki_service.rb b/lib/gitlab/gitaly_client/wiki_service.rb
index 6cb049c1f68..75be7d1f5a0 100644
--- a/lib/gitlab/gitaly_client/wiki_service.rb
+++ b/lib/gitlab/gitaly_client/wiki_service.rb
@@ -85,8 +85,8 @@ module Gitlab
wiki_page_from_iterator(response)
end
- def get_all_pages
- request = Gitaly::WikiGetAllPagesRequest.new(repository: @gitaly_repo)
+ def get_all_pages(limit: 0)
+ request = Gitaly::WikiGetAllPagesRequest.new(repository: @gitaly_repo, limit: limit)
response = GitalyClient.call(@repository.storage, :wiki_service, :wiki_get_all_pages, request, timeout: GitalyClient.medium_timeout)
pages = []
diff --git a/spec/controllers/projects/wikis_controller_spec.rb b/spec/controllers/projects/wikis_controller_spec.rb
index 92addf30307..fed6677935e 100644
--- a/spec/controllers/projects/wikis_controller_spec.rb
+++ b/spec/controllers/projects/wikis_controller_spec.rb
@@ -1,8 +1,35 @@
require 'spec_helper'
describe Projects::WikisController do
- let(:project) { create(:project_empty_repo, :public) }
+ let(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) }
+ let(:wiki) { ProjectWiki.new(project, user) }
+
+ describe 'GET #show' do
+ let(:wiki_title) { 'page-title-test' }
+
+ render_views
+
+ before do
+ create_page(wiki_title, 'hello world')
+ end
+
+ it 'limits the retrieved pages for the sidebar' do
+ sign_in(user)
+
+ expect(controller).to receive(:load_wiki).and_return(wiki)
+
+ # empty? call
+ expect(wiki).to receive(:pages).with(limit: 1).and_call_original
+ # Sidebar entries
+ expect(wiki).to receive(:pages).with(limit: 15).and_call_original
+
+ get :show, namespace_id: project.namespace, project_id: project, id: wiki_title
+
+ expect(response).to have_http_status(:ok)
+ expect(response.body).to include(wiki_title)
+ end
+ end
describe 'POST #preview_markdown' do
it 'renders json in a correct format' do
@@ -13,4 +40,12 @@ describe Projects::WikisController do
expect(JSON.parse(response.body).keys).to match_array(%w(body references))
end
end
+
+ def create_page(name, content)
+ project.wiki.wiki.write_page(name, :markdown, content, commit_details(name))
+ end
+
+ def commit_details(name)
+ Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}")
+ end
end
diff --git a/spec/lib/gitlab/git/wiki_spec.rb b/spec/lib/gitlab/git/wiki_spec.rb
index b63658e1b3b..c5666e4ec61 100644
--- a/spec/lib/gitlab/git/wiki_spec.rb
+++ b/spec/lib/gitlab/git/wiki_spec.rb
@@ -6,6 +6,31 @@ describe Gitlab::Git::Wiki do
let(:project_wiki) { ProjectWiki.new(project, user) }
subject { project_wiki.wiki }
+ describe '#pages' do
+ before do
+ create_page('page1', 'content')
+ create_page('page2', 'content2')
+ end
+
+ after do
+ destroy_page('page1')
+ destroy_page('page2')
+ end
+
+ it 'returns all the pages' do
+ expect(subject.pages.count).to eq(2)
+ expect(subject.pages.first.title).to eq 'page1'
+ expect(subject.pages.last.title).to eq 'page2'
+ end
+
+ it 'returns only one page' do
+ pages = subject.pages(limit: 1)
+
+ expect(pages.count).to eq(1)
+ expect(pages.first.title).to eq 'page1'
+ end
+ end
+
describe '#page' do
before do
create_page('page1', 'content')
diff --git a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb
index 6ad9f5ef766..5f67fe6b952 100644
--- a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb
+++ b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb
@@ -70,6 +70,15 @@ describe Gitlab::GitalyClient::WikiService do
subject
end
+ it 'sends a limit of 0 to wiki_get_all_pages' do
+ expect_any_instance_of(Gitaly::WikiService::Stub)
+ .to receive(:wiki_get_all_pages)
+ .with(gitaly_request_with_params(limit: 0), kind_of(Hash))
+ .and_return([].each)
+
+ subject
+ end
+
it 'concatenates the raw data and returns a pair of WikiPage and WikiPageVersion for each page' do
expect_any_instance_of(Gitaly::WikiService::Stub)
.to receive(:wiki_get_all_pages)
@@ -84,5 +93,18 @@ describe Gitlab::GitalyClient::WikiService do
expect(wiki_page_2.raw_data).to eq('cd')
expect(wiki_page_2_version.format).to eq('markdown')
end
+
+ context 'with limits' do
+ subject { client.get_all_pages(limit: 1) }
+
+ it 'sends a request with the limit' do
+ expect_any_instance_of(Gitaly::WikiService::Stub)
+ .to receive(:wiki_get_all_pages)
+ .with(gitaly_request_with_params(limit: 1), kind_of(Hash))
+ .and_return([].each)
+
+ subject
+ end
+ end
end
end