diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2017-10-23 22:12:11 +0200 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2017-10-31 20:49:41 +0200 |
commit | 56e53556c538236a040dcd0e499cc198d66e7cf6 (patch) | |
tree | 3e334cb5ed1e988af976e15a8f9789fafa5c14ff /lib | |
parent | 0134079430f0179c527d388539c0986352bca9bd (diff) | |
download | gitlab-ce-56e53556c538236a040dcd0e499cc198d66e7cf6.tar.gz |
Migrate Gitlab::Git::Wiki#file to Gitalyfeature/migrate-find-wiki-file-to-gitaly
Closes gitaly#689
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/wiki.rb | 27 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/wiki_file.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/gitaly_client/wiki_service.rb | 26 |
3 files changed, 65 insertions, 5 deletions
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index 549d22adde5..45362ac438b 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -68,11 +68,13 @@ module Gitlab end def file(name, version) - version ||= self.class.default_ref - gollum_file = gollum_wiki.file(name, version) - return unless gollum_file - - Gitlab::Git::WikiFile.new(gollum_file) + @repository.gitaly_migrate(:wiki_find_file) do |is_enabled| + if is_enabled + gitaly_find_file(name, version) + else + gollum_find_file(name, version) + end + end end def page_versions(page_path) @@ -156,6 +158,14 @@ module Gitlab new_page(gollum_page) end + def gollum_find_file(name, version) + version ||= self.class.default_ref + gollum_file = gollum_wiki.file(name, version) + return unless gollum_file + + Gitlab::Git::WikiFile.new(gollum_file) + end + def gitaly_write_page(name, format, content, commit_details) gitaly_wiki_client.write_page(name, format, content, commit_details) end @@ -170,6 +180,13 @@ module Gitlab Gitlab::Git::WikiPage.new(wiki_page, version) 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 end end end diff --git a/lib/gitlab/gitaly_client/wiki_file.rb b/lib/gitlab/gitaly_client/wiki_file.rb new file mode 100644 index 00000000000..a2e415864e6 --- /dev/null +++ b/lib/gitlab/gitaly_client/wiki_file.rb @@ -0,0 +1,17 @@ +module Gitlab + module GitalyClient + class WikiFile + FIELDS = %i(name mime_type path raw_data).freeze + + attr_accessor(*FIELDS) + + def initialize(params) + params = params.with_indifferent_access + + FIELDS.each do |field| + instance_variable_set("@#{field}", params[field]) + end + end + end + end +end diff --git a/lib/gitlab/gitaly_client/wiki_service.rb b/lib/gitlab/gitaly_client/wiki_service.rb index 5d7930f5ff9..15f0f30d303 100644 --- a/lib/gitlab/gitaly_client/wiki_service.rb +++ b/lib/gitlab/gitaly_client/wiki_service.rb @@ -80,6 +80,32 @@ module Gitlab [wiki_page, version] end + def find_file(name, revision) + request = Gitaly::WikiFindFileRequest.new( + repository: @gitaly_repo, + name: GitalyClient.encode(name), + revision: GitalyClient.encode(revision) + ) + + response = GitalyClient.call(@repository.storage, :wiki_service, :wiki_find_file, request) + wiki_file = nil + + response.each do |message| + next unless message.name.present? + + if wiki_file + 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 def gitaly_commit_details(commit_details) |