Commit 3e060c30 authored by Markus Koller's avatar Markus Koller

Merge branch '324165-fj-replace-wiki-find-file-call-with-gitaly' into 'master'

Replace wiki#find_file RPC with Gitaly call [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56321
parents 8bc3ba7a 02d83508
...@@ -159,9 +159,18 @@ class Wiki ...@@ -159,9 +159,18 @@ class Wiki
find_page(SIDEBAR, version) find_page(SIDEBAR, version)
end end
def find_file(name, version = 'HEAD') def find_file(name, version = 'HEAD', load_content: true)
if Feature.enabled?(:gitaly_find_file, user, default_enabled: :yaml)
data_limit = load_content ? -1 : 0
blobs = repository.blobs_at([[version, name]], blob_size_limit: data_limit)
return if blobs.empty?
Gitlab::Git::WikiFile.from_blob(blobs.first)
else
wiki.file(name, version) wiki.file(name, version)
end end
end
def create_page(title, content, format = :markdown, message = nil) def create_page(title, content, format = :markdown, message = nil)
commit = commit_details(:created, message, title) commit = commit_details(:created, message, title)
......
---
name: gitaly_find_file
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/56321
rollout_issue_url:
milestone: '13.10'
type: development
group: group::editor
default_enabled: false
...@@ -100,7 +100,7 @@ module Banzai ...@@ -100,7 +100,7 @@ module Banzai
if url?(content) if url?(content)
path = content path = content
elsif file = wiki.find_file(content) elsif file = wiki.find_file(content, load_content: false)
path = ::File.join(wiki_base_path, file.path) path = ::File.join(wiki_base_path, file.path)
end end
......
...@@ -12,6 +12,19 @@ module Gitlab ...@@ -12,6 +12,19 @@ module Gitlab
@name = gitaly_file.name @name = gitaly_file.name
@path = gitaly_file.path @path = gitaly_file.path
end end
def self.from_blob(blob)
hash = {
name: File.basename(blob.name),
mime_type: blob.mime_type,
path: blob.path,
raw_data: blob.data
}
gitaly_file = Gitlab::GitalyClient::WikiFile.new(hash)
Gitlab::Git::WikiFile.new(gitaly_file)
end
end end
end end
end end
...@@ -56,7 +56,7 @@ RSpec.describe 'GitLab Markdown Benchmark', :aggregate_failures do ...@@ -56,7 +56,7 @@ RSpec.describe 'GitLab Markdown Benchmark', :aggregate_failures do
it 'benchmarks several pipelines' do it 'benchmarks several pipelines' do
path = 'images/example.jpg' path = 'images/example.jpg'
gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path)
allow(wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) allow(wiki).to receive(:find_file).with(path, load_content: false).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file))
allow(wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } allow(wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' }
puts "\n--> Benchmarking Full, Wiki, and Plain pipelines\n" puts "\n--> Benchmarking Full, Wiki, and Plain pipelines\n"
......
...@@ -290,7 +290,7 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do ...@@ -290,7 +290,7 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do
path = 'images/example.jpg' path = 'images/example.jpg'
gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path)
expect(@wiki).to receive(:find_file).with(path).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) expect(@wiki).to receive(:find_file).with(path, load_content: false).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file))
allow(@wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' } allow(@wiki).to receive(:wiki_base_path) { '/namespace1/gitlabhq/wikis' }
@html = markdown(@feat.raw_markdown, { pipeline: :wiki, wiki: @wiki, page_slug: @wiki_page.slug }) @html = markdown(@feat.raw_markdown, { pipeline: :wiki, wiki: @wiki, page_slug: @wiki_page.slug })
......
...@@ -22,7 +22,7 @@ RSpec.describe Banzai::Filter::GollumTagsFilter do ...@@ -22,7 +22,7 @@ RSpec.describe Banzai::Filter::GollumTagsFilter do
path: 'images/image.jpg', path: 'images/image.jpg',
raw_data: '') raw_data: '')
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double) wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
expect(wiki).to receive(:find_file).with('images/image.jpg').and_return(wiki_file) expect(wiki).to receive(:find_file).with('images/image.jpg', load_content: false).and_return(wiki_file)
tag = '[[images/image.jpg]]' tag = '[[images/image.jpg]]'
doc = filter("See #{tag}", wiki: wiki) doc = filter("See #{tag}", wiki: wiki)
...@@ -31,7 +31,7 @@ RSpec.describe Banzai::Filter::GollumTagsFilter do ...@@ -31,7 +31,7 @@ RSpec.describe Banzai::Filter::GollumTagsFilter do
end end
it 'does not creates img tag if image does not exist' do it 'does not creates img tag if image does not exist' do
expect(wiki).to receive(:find_file).with('images/image.jpg').and_return(nil) expect(wiki).to receive(:find_file).with('images/image.jpg', load_content: false).and_return(nil)
tag = '[[images/image.jpg]]' tag = '[[images/image.jpg]]'
doc = filter("See #{tag}", wiki: wiki) doc = filter("See #{tag}", wiki: wiki)
......
...@@ -354,6 +354,7 @@ RSpec.shared_examples 'wiki model' do ...@@ -354,6 +354,7 @@ RSpec.shared_examples 'wiki model' do
subject.repository.create_file(user, 'image.png', image, branch_name: subject.default_branch, message: 'add image') subject.repository.create_file(user, 'image.png', image, branch_name: subject.default_branch, message: 'add image')
end end
shared_examples 'find_file results' do
it 'returns the latest version of the file if it exists' do it 'returns the latest version of the file if it exists' do
file = subject.find_file('image.png') file = subject.find_file('image.png')
...@@ -378,6 +379,25 @@ RSpec.shared_examples 'wiki model' do ...@@ -378,6 +379,25 @@ RSpec.shared_examples 'wiki model' do
end end
end end
it_behaves_like 'find_file results'
context 'when load_content is disabled' do
it 'includes the file data in the Gitlab::Git::WikiFile' do
file = subject.find_file('image.png', load_content: false)
expect(file.raw_data).to be_empty
end
end
context 'when feature flag :gitaly_find_file is disabled' do
before do
stub_feature_flags(gitaly_find_file: false)
end
it_behaves_like 'find_file results'
end
end
describe '#create_page' do describe '#create_page' do
it 'creates a new wiki page' do it 'creates a new wiki page' do
expect(subject.create_page('test page', 'this is content')).not_to eq(false) expect(subject.create_page('test page', 'this is content')).not_to eq(false)
......
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