Allow pagination for WikiVersions on Gitaly request
This commit is contained in:
parent
bd96f2d6e3
commit
a29f0c28fd
3 changed files with 19 additions and 43 deletions
|
@ -285,7 +285,7 @@ GEM
|
|||
po_to_json (>= 1.0.0)
|
||||
rails (>= 3.2.0)
|
||||
gherkin-ruby (0.3.2)
|
||||
gitaly-proto (0.73.0)
|
||||
gitaly-proto (0.74.0)
|
||||
google-protobuf (~> 3.1)
|
||||
grpc (~> 1.0)
|
||||
github-linguist (4.7.6)
|
||||
|
@ -1056,7 +1056,7 @@ DEPENDENCIES
|
|||
gettext (~> 3.2.2)
|
||||
gettext_i18n_rails (~> 1.8.0)
|
||||
gettext_i18n_rails_js (~> 1.2.0)
|
||||
gitaly-proto (~> 0.73.0)
|
||||
gitaly-proto (~> 0.74.0)
|
||||
github-linguist (~> 4.7.0)
|
||||
gitlab-flowdock-git-hook (~> 1.0.1)
|
||||
gitlab-markup (~> 1.6.2)
|
||||
|
|
|
@ -93,15 +93,15 @@ module Gitlab
|
|||
# :per_page - The number of items per page.
|
||||
# :limit - Total number of items to return.
|
||||
def page_versions(page_path, options = {})
|
||||
puts '-' * 80
|
||||
puts options
|
||||
puts '-' * 80
|
||||
puts
|
||||
|
||||
byebug
|
||||
@repository.gitaly_migrate(:wiki_page_versions) do |is_enabled|
|
||||
if is_enabled
|
||||
gitaly_wiki_client.page_versions(page_path, pagination_params(options))
|
||||
versions = gitaly_wiki_client.page_versions(page_path, options)
|
||||
|
||||
# Gitaly uses gollum-lib to get the versions. Gollum defaults to 20
|
||||
# per page, but also fetches 20 if `limit` or `per_page` < 20.
|
||||
# Slicing returns an array with the expected number of items.
|
||||
slice_bound = options[:limit] || options[:per_page] || Gollum::Page.per_page
|
||||
versions[0..slice_bound]
|
||||
else
|
||||
current_page = gollum_page_by_path(page_path)
|
||||
|
||||
|
@ -136,21 +136,15 @@ module Gitlab
|
|||
# :per_page - The number of items per page.
|
||||
# :limit - Total number of items to return.
|
||||
def commits_from_page(gollum_page, options = {})
|
||||
pagination_options = pagination_params(options)
|
||||
unless options[:limit]
|
||||
options[:offset] = ([1, options.delete(:page).to_i].max - 1) * Gollum::Page.per_page
|
||||
options[:limit] = (options.delete(:per_page) || Gollum::Page.per_page).to_i
|
||||
end
|
||||
|
||||
@repository.log(ref: gollum_page.last_version.id,
|
||||
path: gollum_page.path,
|
||||
limit: pagination_options[:limit],
|
||||
offset: pagination_options[:offset])
|
||||
end
|
||||
|
||||
def pagination_params(options)
|
||||
return options if options[:limit]
|
||||
|
||||
options = options.dup
|
||||
options[:offset] = ([1, options.delete(:page).to_i].max - 1) * Gollum::Page.per_page
|
||||
options[:limit] = (options.delete(:per_page) || Gollum::Page.per_page).to_i
|
||||
options
|
||||
limit: options[:limit],
|
||||
offset: options[:offset])
|
||||
end
|
||||
|
||||
def gollum_wiki
|
||||
|
|
|
@ -108,38 +108,20 @@ module Gitlab
|
|||
def page_versions(page_path, options)
|
||||
request = Gitaly::WikiGetPageVersionsRequest.new(
|
||||
repository: @gitaly_repo,
|
||||
page_path: encode_binary(page_path)
|
||||
page_path: encode_binary(page_path),
|
||||
page: options[:page] || 1,
|
||||
per_page: options[:per_page] || Gollum::Page.per_page
|
||||
)
|
||||
|
||||
min_index = options[:offset].to_i
|
||||
max_index = min_index + options[:limit].to_i
|
||||
byebug
|
||||
|
||||
stream = GitalyClient.call(@repository.storage, :wiki_service, :wiki_get_page_versions, request)
|
||||
|
||||
version_index = 0
|
||||
versions = []
|
||||
|
||||
# Allow limit and offset to be send to Gitaly: TODO
|
||||
stream.each do |message|
|
||||
puts '§' * 80
|
||||
puts version_index
|
||||
|
||||
message.versions.each do |version|
|
||||
case version_index
|
||||
when min_index...max_index
|
||||
versions << new_wiki_page_version(version)
|
||||
when max_index..Float::INFINITY
|
||||
return versions
|
||||
end
|
||||
|
||||
version_index += 1
|
||||
puts version_index
|
||||
versions << new_wiki_page_version(version)
|
||||
end
|
||||
end
|
||||
|
||||
# when we're requesting page 99 but the stream doesn't go that far, whatever
|
||||
# is fetched thus far
|
||||
versions
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue