Move wiki list_pages method to Gitaly
Continuing the effort of &2381 (closed), we need to migrate the list_pages
method to Gitaly.
First of all, we should talk about the functionality of this method. It retrieves all pages (along with the last commit info) from the repository. We could retrieve the wiki pages with or without the content.
The functionality to retrieve the content of all wiki pages is not needed anywhere so we can remove it right away.
The list of pages returned are Wiki::Page
that includes the last version (commit) info.
We could implement this in Rails (quick and dirty approach):
def list_pages(limit: 0, sort: nil, direction: DIRECTION_ASC, load_content: false)
# We need to retrieve pages that has valid markup extensions
# We could do that in Gitaly or filter them later in Rails
files = repository.ls_files('HEAD').map { |f| ['HEAD', f] }
blobs = repository.blobs_at(files, blob_size_limit: 0)
blobs.map do |blob|
gitaly_page = Gitlab::GitalyClient::WikiPage.from_blob(blob)
commit = repository.raw_repository.last_commit_for_path('HEAD', blob.path)
version = Gitlab::Git::WikiPageVersion.new(commit, gitaly_page.format)
git_wiki_page = Gitlab::Git::WikiPage.new(gitaly_page, version)
WikiPage.new(self, git_wiki_page)
end
end
The main concern I have is that if we have 100 pages in the wiki we will perform 102 RPC calls to Gitaly. 1 to retrieve all pages (ls_files
), 1 to retrieve the blobs info, and 100 to retrieve the last commit info.
I think it would be better if we could implement an endpoint in Gitaly to return all the necessary information because the Rails approach doesn't scale.