Merge branch 'feature/migrate-wiki-delete-page-to-gitaly' into 'master'

Migrate Gitlab::Git::Wiki#delete_page to Gitaly

Closes gitaly#673

See merge request gitlab-org/gitlab-ce!14910
This commit is contained in:
Sean McGivern 2017-10-31 14:35:57 +00:00
commit bd33a8290a
7 changed files with 69 additions and 28 deletions

View file

@ -1 +1 @@
0.50.0
0.51.0

View file

@ -398,7 +398,7 @@ group :ed25519 do
end
# Gitaly GRPC client
gem 'gitaly-proto', '~> 0.48.0', require: 'gitaly'
gem 'gitaly-proto', '~> 0.51.0', require: 'gitaly'
gem 'toml-rb', '~> 0.3.15', require: false

View file

@ -273,7 +273,7 @@ GEM
po_to_json (>= 1.0.0)
rails (>= 3.2.0)
gherkin-ruby (0.3.2)
gitaly-proto (0.48.0)
gitaly-proto (0.51.0)
google-protobuf (~> 3.1)
grpc (~> 1.0)
github-linguist (4.7.6)
@ -1030,7 +1030,7 @@ DEPENDENCIES
gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.48.0)
gitaly-proto (~> 0.51.0)
github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.6.2)

View file

@ -35,10 +35,14 @@ module Gitlab
end
def delete_page(page_path, commit_details)
assert_type!(commit_details, CommitDetails)
gollum_wiki.delete_page(gollum_page_by_path(page_path), commit_details.to_h)
nil
@repository.gitaly_migrate(:wiki_delete_page) do |is_enabled|
if is_enabled
gitaly_delete_page(page_path, commit_details)
gollum_wiki.clear_cache
else
gollum_delete_page(page_path, commit_details)
end
end
end
def update_page(page_path, title, format, content, commit_details)
@ -135,9 +139,20 @@ module Gitlab
raise Gitlab::Git::Wiki::DuplicatePageError, e.message
end
def gollum_delete_page(page_path, commit_details)
assert_type!(commit_details, CommitDetails)
gollum_wiki.delete_page(gollum_page_by_path(page_path), commit_details.to_h)
nil
end
def gitaly_write_page(name, format, content, commit_details)
gitaly_wiki_client.write_page(name, format, content, commit_details)
end
def gitaly_delete_page(page_path, commit_details)
gitaly_wiki_client.delete_page(page_path, commit_details)
end
end
end
end

View file

@ -15,11 +15,7 @@ module Gitlab
repository: @gitaly_repo,
name: GitalyClient.encode(name),
format: format.to_s,
commit_details: Gitaly::WikiCommitDetails.new(
name: GitalyClient.encode(commit_details.name),
email: GitalyClient.encode(commit_details.email),
message: GitalyClient.encode(commit_details.message)
)
commit_details: gitaly_commit_details(commit_details)
)
strio = StringIO.new(content)
@ -40,6 +36,26 @@ module Gitlab
raise Gitlab::Git::Wiki::DuplicatePageError, error
end
end
def delete_page(page_path, commit_details)
request = Gitaly::WikiDeletePageRequest.new(
repository: @gitaly_repo,
page_path: GitalyClient.encode(page_path),
commit_details: gitaly_commit_details(commit_details)
)
GitalyClient.call(@repository.storage, :wiki_service, :wiki_delete_page, request)
end
private
def gitaly_commit_details(commit_details)
Gitaly::WikiCommitDetails.new(
name: GitalyClient.encode(commit_details.name),
email: GitalyClient.encode(commit_details.email),
message: GitalyClient.encode(commit_details.message)
)
end
end
end
end

View file

@ -265,23 +265,33 @@ describe ProjectWiki do
end
describe "#delete_page" do
before do
create_page("index", "some content")
@page = subject.wiki.page(title: "index")
shared_examples 'deleting a wiki page' do
before do
create_page("index", "some content")
@page = subject.wiki.page(title: "index")
end
it "deletes the page" do
subject.delete_page(@page)
expect(subject.pages.count).to eq(0)
end
it 'updates project activity' do
subject.delete_page(@page)
project.reload
expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
end
end
it "deletes the page" do
subject.delete_page(@page)
expect(subject.pages.count).to eq(0)
context 'when Gitaly wiki_delete_page is enabled' do
it_behaves_like 'deleting a wiki page'
end
it 'updates project activity' do
subject.delete_page(@page)
project.reload
expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
context 'when Gitaly wiki_delete_page is disabled', :skip_gitaly_mock do
it_behaves_like 'deleting a wiki page'
end
end
@ -343,6 +353,6 @@ describe ProjectWiki do
end
def destroy_page(page)
subject.delete_page(page, commit_details)
subject.delete_page(page, "test commit")
end
end

View file

@ -402,7 +402,7 @@ describe WikiPage do
def destroy_page(title)
page = wiki.wiki.page(title: title)
wiki.delete_page(page, commit_details)
wiki.delete_page(page, "test commit")
end
def get_slugs(page_or_dir)