Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
964cbb67
Commit
964cbb67
authored
Oct 19, 2017
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate Gitlab::Git::Wiki#page to Gitaly
Closes gitaly#677
parent
bd33a829
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
110 additions
and
25 deletions
+110
-25
lib/gitlab/git/wiki.rb
lib/gitlab/git/wiki.rb
+24
-7
lib/gitlab/gitaly_client/wiki_page.rb
lib/gitlab/gitaly_client/wiki_page.rb
+25
-0
lib/gitlab/gitaly_client/wiki_service.rb
lib/gitlab/gitaly_client/wiki_service.rb
+33
-0
spec/models/project_wiki_spec.rb
spec/models/project_wiki_spec.rb
+28
-18
No files found.
lib/gitlab/git/wiki.rb
View file @
964cbb67
...
@@ -58,14 +58,13 @@ module Gitlab
...
@@ -58,14 +58,13 @@ module Gitlab
end
end
def
page
(
title
:,
version:
nil
,
dir:
nil
)
def
page
(
title
:,
version:
nil
,
dir:
nil
)
if
version
@repository
.
gitaly_migrate
(
:wiki_find_page
)
do
|
is_enabled
|
version
=
Gitlab
::
Git
::
Commit
.
find
(
@repository
,
version
).
id
if
is_enabled
gitaly_find_page
(
title:
title
,
version:
version
,
dir:
dir
)
else
gollum_find_page
(
title:
title
,
version:
version
,
dir:
dir
)
end
end
end
gollum_page
=
gollum_wiki
.
page
(
title
,
version
,
dir
)
return
unless
gollum_page
new_page
(
gollum_page
)
end
end
def
file
(
name
,
version
)
def
file
(
name
,
version
)
...
@@ -146,6 +145,17 @@ module Gitlab
...
@@ -146,6 +145,17 @@ module Gitlab
nil
nil
end
end
def
gollum_find_page
(
title
:,
version:
nil
,
dir:
nil
)
if
version
version
=
Gitlab
::
Git
::
Commit
.
find
(
@repository
,
version
).
id
end
gollum_page
=
gollum_wiki
.
page
(
title
,
version
,
dir
)
return
unless
gollum_page
new_page
(
gollum_page
)
end
def
gitaly_write_page
(
name
,
format
,
content
,
commit_details
)
def
gitaly_write_page
(
name
,
format
,
content
,
commit_details
)
gitaly_wiki_client
.
write_page
(
name
,
format
,
content
,
commit_details
)
gitaly_wiki_client
.
write_page
(
name
,
format
,
content
,
commit_details
)
end
end
...
@@ -153,6 +163,13 @@ module Gitlab
...
@@ -153,6 +163,13 @@ module Gitlab
def
gitaly_delete_page
(
page_path
,
commit_details
)
def
gitaly_delete_page
(
page_path
,
commit_details
)
gitaly_wiki_client
.
delete_page
(
page_path
,
commit_details
)
gitaly_wiki_client
.
delete_page
(
page_path
,
commit_details
)
end
end
def
gitaly_find_page
(
title
:,
version:
nil
,
dir:
nil
)
wiki_page
,
version
=
gitaly_wiki_client
.
find_page
(
title:
title
,
version:
version
,
dir:
dir
)
return
unless
wiki_page
Gitlab
::
Git
::
WikiPage
.
new
(
wiki_page
,
version
)
end
end
end
end
end
end
end
lib/gitlab/gitaly_client/wiki_page.rb
0 → 100644
View file @
964cbb67
module
Gitlab
module
GitalyClient
class
WikiPage
FIELDS
=
%i(title format url_path path name historical raw_data)
.
freeze
attr_accessor
(
*
FIELDS
)
def
initialize
(
params
)
params
=
params
.
with_indifferent_access
FIELDS
.
each
do
|
field
|
instance_variable_set
(
"@
#{
field
}
"
,
params
[
field
])
end
end
def
historical?
@historical
end
def
format
@format
.
to_sym
end
end
end
end
lib/gitlab/gitaly_client/wiki_service.rb
View file @
964cbb67
...
@@ -47,6 +47,39 @@ module Gitlab
...
@@ -47,6 +47,39 @@ module Gitlab
GitalyClient
.
call
(
@repository
.
storage
,
:wiki_service
,
:wiki_delete_page
,
request
)
GitalyClient
.
call
(
@repository
.
storage
,
:wiki_service
,
:wiki_delete_page
,
request
)
end
end
def
find_page
(
title
:,
version:
nil
,
dir:
nil
)
request
=
Gitaly
::
WikiFindPageRequest
.
new
(
repository:
@gitaly_repo
,
title:
GitalyClient
.
encode
(
title
),
revision:
GitalyClient
.
encode
(
version
),
directory:
GitalyClient
.
encode
(
dir
)
)
response
=
GitalyClient
.
call
(
@repository
.
storage
,
:wiki_service
,
:wiki_find_page
,
request
)
wiki_page
=
version
=
nil
response
.
each
do
|
message
|
page
=
message
.
page
next
unless
page
if
wiki_page
wiki_page
.
raw_data
<<
page
.
raw_data
else
wiki_page
=
GitalyClient
::
WikiPage
.
new
(
page
.
to_h
)
# All gRPC strings in a response are frozen, so we get
# an unfrozen version here so appending in the else clause below doesn't blow up.
wiki_page
.
raw_data
=
wiki_page
.
raw_data
.
dup
version
=
Gitlab
::
Git
::
WikiPageVersion
.
new
(
Gitlab
::
Git
::
Commit
.
decorate
(
@repository
,
page
.
version
.
commit
),
page
.
version
.
format
)
end
end
[
wiki_page
,
version
]
end
private
private
def
gitaly_commit_details
(
commit_details
)
def
gitaly_commit_details
(
commit_details
)
...
...
spec/models/project_wiki_spec.rb
View file @
964cbb67
...
@@ -117,31 +117,41 @@ describe ProjectWiki do
...
@@ -117,31 +117,41 @@ describe ProjectWiki do
end
end
describe
"#find_page"
do
describe
"#find_page"
do
before
do
shared_examples
'finding a wiki page'
do
create_page
(
"index page"
,
"This is an awesome Gollum Wiki"
)
before
do
end
create_page
(
"index page"
,
"This is an awesome Gollum Wiki"
)
end
after
do
after
do
destroy_page
(
subject
.
pages
.
first
.
page
)
destroy_page
(
subject
.
pages
.
first
.
page
)
end
end
it
"returns the latest version of the page if it exists"
do
it
"returns the latest version of the page if it exists"
do
page
=
subject
.
find_page
(
"index page"
)
page
=
subject
.
find_page
(
"index page"
)
expect
(
page
.
title
).
to
eq
(
"index page"
)
expect
(
page
.
title
).
to
eq
(
"index page"
)
end
end
it
"returns nil if the page does not exist"
do
expect
(
subject
.
find_page
(
"non-existant"
)).
to
eq
(
nil
)
end
it
"can find a page by slug"
do
page
=
subject
.
find_page
(
"index-page"
)
expect
(
page
.
title
).
to
eq
(
"index page"
)
end
it
"returns nil if the page does not exist"
do
it
"returns a WikiPage instance"
do
expect
(
subject
.
find_page
(
"non-existant"
)).
to
eq
(
nil
)
page
=
subject
.
find_page
(
"index page"
)
expect
(
page
).
to
be_a
WikiPage
end
end
end
it
"can find a page by slug"
do
context
'when Gitaly wiki_find_page is enabled'
do
page
=
subject
.
find_page
(
"index-page"
)
it_behaves_like
'finding a wiki page'
expect
(
page
.
title
).
to
eq
(
"index page"
)
end
end
it
"returns a WikiPage instance"
do
context
'when Gitaly wiki_find_page is disabled'
,
:skip_gitaly_mock
do
page
=
subject
.
find_page
(
"index page"
)
it_behaves_like
'finding a wiki page'
expect
(
page
).
to
be_a
WikiPage
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment