diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2019-04-25 07:19:07 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-04-25 07:19:07 +0300 |
commit | dde69bfb2a595956c54ddb9c776759c11b3f2a3b (patch) | |
tree | 70629de9baf0f34a2bf2bc71e9045bc0366ec24c /lib/gitlab/git | |
parent | 0f863c68bb8bc5054a22e0c553a933c83bea4df6 (diff) |
Added list_pages method to avoid loading all wiki pages content
Inside a wiki, when we show the sidebar or browse to the `pages`,
all page contents are retrieved from Gitaly and that is a waste
of resources, since no content from that pages are going to be
showed.
This MR introduces the method `ProjectWiki#list_pages`,
which uses new wiki_list_pages RPC call to retrieve
pages without content
Also in the `WikisController` we're using the method to show
pages in the sidebar and also on the `pages` page.
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r-- | lib/gitlab/git/wiki.rb | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/gitlab/git/wiki.rb b/lib/gitlab/git/wiki.rb index a0dd4a24363..c1bcd8e934a 100644 --- a/lib/gitlab/git/wiki.rb +++ b/lib/gitlab/git/wiki.rb @@ -86,9 +86,14 @@ module Gitlab end end - def pages(limit: 0, sort: nil, direction_desc: false) + def list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false) wrapped_gitaly_errors do - gitaly_get_all_pages(limit: limit, sort: sort, direction_desc: direction_desc) + gitaly_list_pages( + limit: limit, + sort: sort, + direction_desc: direction_desc, + load_content: load_content + ) end end @@ -168,10 +173,17 @@ module Gitlab Gitlab::Git::WikiFile.new(wiki_file) end - def gitaly_get_all_pages(limit: 0, sort: nil, direction_desc: false) - gitaly_wiki_client.get_all_pages( - limit: limit, sort: sort, direction_desc: direction_desc - ).map do |wiki_page, version| + def gitaly_list_pages(limit: 0, sort: nil, direction_desc: false, load_content: false) + params = { limit: limit, sort: sort, direction_desc: direction_desc } + + gitaly_pages = + if load_content + gitaly_wiki_client.load_all_pages(params) + else + gitaly_wiki_client.list_all_pages(params) + end + + gitaly_pages.map do |wiki_page, version| Gitlab::Git::WikiPage.new(wiki_page, version) end end |