Commit c97e9f4f authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch '336792-fj-update-find-page-params-to-use-load-content' into 'master'

Adapt find page method to accept new skip_content RPC param

See merge request gitlab-org/gitlab!81513
parents 32141377 2d562fb2
......@@ -476,7 +476,7 @@ gem 'ssh_data', '~> 1.2'
gem 'spamcheck', '~> 0.1.0'
# Gitaly GRPC protocol definitions
gem 'gitaly', '~> 14.8.0.pre.rc1'
gem 'gitaly', '~> 14.9.0.pre.rc2'
# KAS GRPC protocol definitions
gem 'kas-grpc', '~> 0.0.2'
......
......@@ -455,7 +455,7 @@ GEM
rails (>= 3.2.0)
git (1.7.0)
rchardet (~> 1.8)
gitaly (14.8.0.pre.rc1)
gitaly (14.9.0.pre.rc2)
grpc (~> 1.0)
github-markup (1.7.0)
gitlab (4.16.1)
......@@ -1475,7 +1475,7 @@ DEPENDENCIES
gettext (~> 3.3)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.3)
gitaly (~> 14.8.0.pre.rc1)
gitaly (~> 14.9.0.pre.rc2)
github-markup (~> 1.7.0)
gitlab-chronic (~> 0.10.5)
gitlab-dangerfiles (~> 2.10.2)
......
......@@ -150,10 +150,10 @@ class Wiki
# the page.
#
# Returns an initialized WikiPage instance or nil
def find_page(title, version = nil)
def find_page(title, version = nil, load_content: true)
page_title, page_dir = page_title_and_dir(title)
if page = wiki.page(title: page_title, version: version, dir: page_dir)
if page = wiki.page(title: page_title, version: version, dir: page_dir, load_content: load_content)
WikiPage.new(self, page)
end
end
......
......@@ -93,9 +93,9 @@ module Gitlab
end
end
def page(title:, version: nil, dir: nil)
def page(title:, version: nil, dir: nil, load_content: true)
wrapped_gitaly_errors do
gitaly_find_page(title: title, version: version, dir: dir)
gitaly_find_page(title: title, version: version, dir: dir, load_content: load_content)
end
end
......@@ -121,10 +121,10 @@ module Gitlab
gitaly_wiki_client.update_page(page_path, title, format, content, commit_details)
end
def gitaly_find_page(title:, version: nil, dir: nil)
def gitaly_find_page(title:, version: nil, dir: nil, load_content: true)
return unless title.present?
wiki_page, version = gitaly_wiki_client.find_page(title: title, version: version, dir: dir)
wiki_page, version = gitaly_wiki_client.find_page(title: title, version: version, dir: dir, load_content: load_content)
return unless wiki_page
Gitlab::Git::WikiPage.new(wiki_page, version)
......
......@@ -64,12 +64,13 @@ module Gitlab
GitalyClient.call(@repository.storage, :wiki_service, :wiki_update_page, enum, timeout: GitalyClient.medium_timeout)
end
def find_page(title:, version: nil, dir: nil)
def find_page(title:, version: nil, dir: nil, load_content: true)
request = Gitaly::WikiFindPageRequest.new(
repository: @gitaly_repo,
title: encode_binary(title),
revision: encode_binary(version),
directory: encode_binary(dir)
directory: encode_binary(dir),
skip_content: !load_content
)
response = GitalyClient.call(@repository.storage, :wiki_service, :wiki_find_page, request, timeout: GitalyClient.fast_timeout)
......
......@@ -48,14 +48,26 @@ RSpec.describe Gitlab::Git::Wiki do
end
it 'returns the right page' do
expect(subject.page(title: 'page1', dir: '').url_path).to eq 'page1'
expect(subject.page(title: 'page1', dir: 'foo').url_path).to eq 'foo/page1'
page = subject.page(title: 'page1', dir: '')
expect(page.url_path).to eq 'page1'
expect(page.raw_data).to eq 'content'
page = subject.page(title: 'page1', dir: 'foo')
expect(page.url_path).to eq 'foo/page1'
expect(page.raw_data).to eq 'content foo/page1'
end
it 'returns nil for invalid arguments' do
expect(subject.page(title: '')).to be_nil
expect(subject.page(title: 'foo', version: ':')).to be_nil
end
it 'does not return content if load_content param is set to false' do
page = subject.page(title: 'page1', dir: '', load_content: false)
expect(page.url_path).to eq 'page1'
expect(page.raw_data).to be_empty
end
end
describe '#preview_slug' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment