Move wiki find_page method to Gitaly
Continuing the effort of &2381 (closed), we need to migrate the find_page
method to Gitaly.
We could do that entirely in Rails like the following (this a quick and dirty approach):
def find_page(title, version = nil)
revision = version.presence || 'HEAD'
# This should be done differently because we need to consider other valid extensions, sluggify title, ...
# We could also call `search_files_by_wildcard_path` instead of `blob_at`
blob = repository.blob_at(revision, title, blob_size_limit: -1)
return unless blob
blob = blobs.first
gitaly_page = Gitlab::GitalyClient::WikiPage.from_blob(blob)
commit = repository.raw_repository.last_commit_for_path(revision, blob.path)
version = Gitlab::Git::WikiPageVersion.new(commit, guess_content_type(blob.name))
git_wiki_page = Gitlab::Git::WikiPage.new(gitaly_page, version)
WikiPage.new(self, git_wiki_page)
end
With these changes, we would need from 2 to 3 RPC calls per each call to find_page
.
Ideally, we would do this in a single RPC call, avoiding the burden of several calls. Nevertheless, the definition of the RPC endpoint would be quite strange since we would need to pass the sluggified title and the valid regex extensions, unless we build a regex in Rails and pass it to find_page
. With also the Gitaly endpoint we could get the commit info right away with the wiki page.
Edited by Francisco Javier López (ex-Gitlab)