parent
bd7a387b43
commit
1c0437d95e
|
@ -76,7 +76,7 @@ class Projects::WikisController < Projects::ApplicationController
|
|||
@page = @project_wiki.find_page(params[:id])
|
||||
|
||||
if @page
|
||||
@page_versions = Kaminari.paginate_array(@page.versions(page: params[:page]),
|
||||
@page_versions = Kaminari.paginate_array(@page.versions(page: params[:page].to_i),
|
||||
total_count: @page.count_versions)
|
||||
.page(params[:page])
|
||||
else
|
||||
|
|
|
@ -93,6 +93,16 @@ 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))
|
||||
else
|
||||
current_page = gollum_page_by_path(page_path)
|
||||
|
||||
commits_from_page(current_page, options).map do |gitlab_git_commit|
|
||||
|
@ -100,6 +110,8 @@ module Gitlab
|
|||
Gitlab::Git::WikiPageVersion.new(gitlab_git_commit, gollum_page&.format)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def count_page_versions(page_path)
|
||||
@repository.count_commits(ref: 'HEAD', path: page_path)
|
||||
|
@ -124,15 +136,21 @@ module Gitlab
|
|||
# :per_page - The number of items per page.
|
||||
# :limit - Total number of items to return.
|
||||
def commits_from_page(gollum_page, 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
|
||||
pagination_options = pagination_params(options)
|
||||
|
||||
@repository.log(ref: gollum_page.last_version.id,
|
||||
path: gollum_page.path,
|
||||
limit: options[:limit],
|
||||
offset: options[:offset])
|
||||
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
|
||||
end
|
||||
|
||||
def gollum_wiki
|
||||
|
|
|
@ -101,6 +101,48 @@ module Gitlab
|
|||
pages
|
||||
end
|
||||
|
||||
# options:
|
||||
# :page - The Integer page number.
|
||||
# :per_page - The number of items per page.
|
||||
# :limit - Total number of items to return.
|
||||
def page_versions(page_path, options)
|
||||
request = Gitaly::WikiGetPageVersionsRequest.new(
|
||||
repository: @gitaly_repo,
|
||||
page_path: encode_binary(page_path)
|
||||
)
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
# when we're requesting page 99 but the stream doesn't go that far, whatever
|
||||
# is fetched thus far
|
||||
versions
|
||||
end
|
||||
|
||||
def find_file(name, revision)
|
||||
request = Gitaly::WikiFindFileRequest.new(
|
||||
repository: @gitaly_repo,
|
||||
|
@ -129,7 +171,7 @@ module Gitlab
|
|||
|
||||
private
|
||||
|
||||
# If a block is given and the yielded value is true, iteration will be
|
||||
# If a block is given and the yielded value is truthy, iteration will be
|
||||
# stopped early at that point; else the iterator is consumed entirely.
|
||||
# The iterator is traversed with `next` to allow resuming the iteration.
|
||||
def wiki_page_from_iterator(iterator)
|
||||
|
@ -146,10 +188,7 @@ module Gitlab
|
|||
else
|
||||
wiki_page = GitalyClient::WikiPage.new(page.to_h)
|
||||
|
||||
version = Gitlab::Git::WikiPageVersion.new(
|
||||
Gitlab::Git::Commit.decorate(@repository, page.version.commit),
|
||||
page.version.format
|
||||
)
|
||||
version = new_wiki_page_version(page.version)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -158,6 +197,13 @@ module Gitlab
|
|||
[wiki_page, version]
|
||||
end
|
||||
|
||||
def new_wiki_page_version(version)
|
||||
Gitlab::Git::WikiPageVersion.new(
|
||||
Gitlab::Git::Commit.decorate(@repository, version.commit),
|
||||
version.format
|
||||
)
|
||||
end
|
||||
|
||||
def gitaly_commit_details(commit_details)
|
||||
Gitaly::WikiCommitDetails.new(
|
||||
name: encode_binary(commit_details.name),
|
||||
|
|
|
@ -252,9 +252,11 @@ describe WikiPage do
|
|||
end
|
||||
|
||||
describe "#versions" do
|
||||
shared_examples 'wiki page versions' do
|
||||
let(:page) { wiki.find_page("Update") }
|
||||
|
||||
before do
|
||||
create_page("Update", "content")
|
||||
@page = wiki.find_page("Update")
|
||||
end
|
||||
|
||||
after do
|
||||
|
@ -262,8 +264,22 @@ describe WikiPage do
|
|||
end
|
||||
|
||||
it "returns an array of all commits for the page" do
|
||||
3.times { |i| @page.update(content: "content #{i}") }
|
||||
expect(@page.versions.count).to eq(4)
|
||||
3.times { |i| page.update(content: "content #{i}") }
|
||||
|
||||
expect(page.versions.count).to eq(4)
|
||||
end
|
||||
|
||||
it 'returns instances of WikiPageVersion' do
|
||||
expect(page.versions).to all( be_a(Gitlab::Git::WikiPageVersion) )
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Gitaly is enabled' do
|
||||
it_behaves_like 'wiki page versions'
|
||||
end
|
||||
|
||||
context 'when Gitaly is disabled', :disable_gitaly do
|
||||
it_behaves_like 'wiki page versions'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue