Commit d3f46313 authored by Markus Koller's avatar Markus Koller

Merge branch '324306-fj-enable-gitaly-find-file-feature-flag' into 'master'

Enable new RPC call to retrieve wiki files [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56491
parents 1ff17bc2 9a7a66c3
...@@ -160,16 +160,12 @@ class Wiki ...@@ -160,16 +160,12 @@ class Wiki
end end
def find_file(name, version = 'HEAD', load_content: true) 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
data_limit = load_content ? -1 : 0 blobs = repository.blobs_at([[version, name]], blob_size_limit: data_limit)
blobs = repository.blobs_at([[version, name]], blob_size_limit: data_limit)
return if blobs.empty? return if blobs.empty?
Gitlab::Git::WikiFile.from_blob(blobs.first) Gitlab::Git::WikiFile.new(blobs.first)
else
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)
......
---
title: Enable new RPC call to retrieve wiki files
merge_request: 56491
author:
type: changed
---
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
...@@ -102,12 +102,6 @@ module Gitlab ...@@ -102,12 +102,6 @@ module Gitlab
end end
end end
def file(name, version)
wrapped_gitaly_errors do
gitaly_find_file(name, version)
end
end
# options: # options:
# :page - The Integer page number. # :page - The Integer page number.
# :per_page - The number of items per page. # :per_page - The number of items per page.
...@@ -161,13 +155,6 @@ module Gitlab ...@@ -161,13 +155,6 @@ module Gitlab
nil nil
end end
def gitaly_find_file(name, version)
wiki_file = gitaly_wiki_client.find_file(name, version)
return unless wiki_file
Gitlab::Git::WikiFile.new(wiki_file)
end
def gitaly_list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false) def gitaly_list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false)
params = { limit: limit, sort: sort, direction_desc: direction_desc } params = { limit: limit, sort: sort, direction_desc: direction_desc }
......
...@@ -5,25 +5,11 @@ module Gitlab ...@@ -5,25 +5,11 @@ module Gitlab
class WikiFile class WikiFile
attr_reader :mime_type, :raw_data, :name, :path attr_reader :mime_type, :raw_data, :name, :path
# This class wraps Gitlab::GitalyClient::WikiFile def initialize(blob)
def initialize(gitaly_file) @mime_type = blob.mime_type
@mime_type = gitaly_file.mime_type @raw_data = blob.data
@raw_data = gitaly_file.raw_data @name = File.basename(blob.name)
@name = gitaly_file.name @path = blob.path
@path = gitaly_file.path
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
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Gitlab module Gitlab
module GitalyClient module GitalyClient
# This module expects an `ATTRS` const to be defined on the subclass # This module expects an `ATTRS` const to be defined on the subclass
# See GitalyClient::WikiFile for an example # See GitalyClient::WikiPage for an example
module AttributesBag module AttributesBag
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
module Gitlab
module GitalyClient
class WikiFile
ATTRS = %i(name mime_type path raw_data).freeze
include AttributesBag
end
end
end
...@@ -153,32 +153,6 @@ module Gitlab ...@@ -153,32 +153,6 @@ module Gitlab
versions versions
end end
def find_file(name, revision)
request = Gitaly::WikiFindFileRequest.new(
repository: @gitaly_repo,
name: encode_binary(name),
revision: encode_binary(revision)
)
response = GitalyClient.call(@repository.storage, :wiki_service, :wiki_find_file, request, timeout: GitalyClient.fast_timeout)
wiki_file = nil
response.each do |message|
next unless message.name.present? || wiki_file
if wiki_file
wiki_file.raw_data = "#{wiki_file.raw_data}#{message.raw_data}"
else
wiki_file = GitalyClient::WikiFile.new(message.to_h)
# All gRPC strings in a response are frozen, so we get
# an unfrozen version here so appending in the else clause below doesn't blow up.
wiki_file.raw_data = wiki_file.raw_data.dup
end
end
wiki_file
end
private private
# If a block is given and the yielded value is truthy, iteration will be # If a block is given and the yielded value is truthy, iteration will be
......
...@@ -54,9 +54,10 @@ RSpec.describe 'GitLab Markdown Benchmark', :aggregate_failures do ...@@ -54,9 +54,10 @@ RSpec.describe 'GitLab Markdown Benchmark', :aggregate_failures do
context 'pipelines' do context 'pipelines' do
it 'benchmarks several pipelines' do it 'benchmarks several pipelines' do
path = 'images/example.jpg' name = 'example.jpg'
gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) path = "images/#{name}"
allow(wiki).to receive(:find_file).with(path, load_content: false).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) blob = double(name: name, path: path, mime_type: 'image/jpeg', data: nil)
allow(wiki).to receive(:find_file).with(path, load_content: false).and_return(Gitlab::Git::WikiFile.new(blob))
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"
......
...@@ -288,9 +288,10 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do ...@@ -288,9 +288,10 @@ RSpec.describe 'GitLab Markdown', :aggregate_failures do
@wiki = @feat.wiki @wiki = @feat.wiki
@wiki_page = @feat.wiki_page @wiki_page = @feat.wiki_page
path = 'images/example.jpg' name = 'example.jpg'
gitaly_wiki_file = Gitlab::GitalyClient::WikiFile.new(path: path) path = "images/#{name}"
expect(@wiki).to receive(:find_file).with(path, load_content: false).and_return(Gitlab::Git::WikiFile.new(gitaly_wiki_file)) blob = double(name: name, path: path, mime_type: 'image/jpeg', data: nil)
expect(@wiki).to receive(:find_file).with(path, load_content: false).and_return(Gitlab::Git::WikiFile.new(blob))
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 })
......
...@@ -16,12 +16,8 @@ RSpec.describe Banzai::Filter::GollumTagsFilter do ...@@ -16,12 +16,8 @@ RSpec.describe Banzai::Filter::GollumTagsFilter do
context 'linking internal images' do context 'linking internal images' do
it 'creates img tag if image exists' do it 'creates img tag if image exists' do
gollum_file_double = double('Gollum::File', blob = double(mime_type: 'image/jpeg', name: 'images/image.jpg', path: 'images/image.jpg', data: '')
mime_type: 'image/jpeg', wiki_file = Gitlab::Git::WikiFile.new(blob)
name: 'images/image.jpg',
path: 'images/image.jpg',
raw_data: '')
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
expect(wiki).to receive(:find_file).with('images/image.jpg', load_content: false).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]]'
......
...@@ -297,7 +297,7 @@ RSpec.describe Banzai::Pipeline::WikiPipeline do ...@@ -297,7 +297,7 @@ RSpec.describe Banzai::Pipeline::WikiPipeline do
mime_type: 'image/jpeg', mime_type: 'image/jpeg',
name: 'images/image.jpg', name: 'images/image.jpg',
path: 'images/image.jpg', path: 'images/image.jpg',
raw_data: '') data: '')
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double) wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
markdown = "[[#{wiki_file.path}]]" markdown = "[[#{wiki_file.path}]]"
......
...@@ -354,33 +354,29 @@ RSpec.shared_examples 'wiki model' do ...@@ -354,33 +354,29 @@ 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')
expect(file.mime_type).to eq('image/png') expect(file.mime_type).to eq('image/png')
end end
it 'returns nil if the page does not exist' do it 'returns nil if the page does not exist' do
expect(subject.find_file('non-existent')).to eq(nil) expect(subject.find_file('non-existent')).to eq(nil)
end end
it 'returns a Gitlab::Git::WikiFile instance' do it 'returns a Gitlab::Git::WikiFile instance' do
file = subject.find_file('image.png') file = subject.find_file('image.png')
expect(file).to be_a Gitlab::Git::WikiFile expect(file).to be_a Gitlab::Git::WikiFile
end end
it 'returns the whole file' do it 'returns the whole file' do
file = subject.find_file('image.png') file = subject.find_file('image.png')
image.rewind image.rewind
expect(file.raw_data.b).to eq(image.read.b) expect(file.raw_data.b).to eq(image.read.b)
end
end end
it_behaves_like 'find_file results'
context 'when load_content is disabled' do context 'when load_content is disabled' do
it 'includes the file data in the Gitlab::Git::WikiFile' do it 'includes the file data in the Gitlab::Git::WikiFile' do
file = subject.find_file('image.png', load_content: false) file = subject.find_file('image.png', load_content: false)
...@@ -388,14 +384,6 @@ RSpec.shared_examples 'wiki model' do ...@@ -388,14 +384,6 @@ RSpec.shared_examples 'wiki model' do
expect(file.raw_data).to be_empty expect(file.raw_data).to be_empty
end end
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 end
describe '#create_page' do describe '#create_page' 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