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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
d9833890
Commit
d9833890
authored
Sep 04, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bulk-render commit titles in the tree view to improve performance
parent
228d819b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
4 deletions
+34
-4
app/controllers/projects/refs_controller.rb
app/controllers/projects/refs_controller.rb
+11
-1
app/models/commit.rb
app/models/commit.rb
+7
-1
app/views/projects/tree/_tree_commit_column.html.haml
app/views/projects/tree/_tree_commit_column.html.haml
+1
-1
spec/features/projects/tree/tree_show_spec.rb
spec/features/projects/tree/tree_show_spec.rb
+15
-1
No files found.
app/controllers/projects/refs_controller.rb
View file @
d9833890
...
@@ -59,13 +59,18 @@ class Projects::RefsController < Projects::ApplicationController
...
@@ -59,13 +59,18 @@ class Projects::RefsController < Projects::ApplicationController
commit_path
=
project_commit_path
(
@project
,
last_commit
)
if
last_commit
commit_path
=
project_commit_path
(
@project
,
last_commit
)
if
last_commit
{
{
file_name:
content
.
name
,
file_name:
content
.
name
,
commit:
last_commit
,
# TODO: deduplicate commits so we don't render the same one multiple times
commit:
(
Commit
.
new
(
last_commit
,
project
)
if
last_commit
),
type:
content
.
type
,
type:
content
.
type
,
commit_path:
commit_path
commit_path:
commit_path
}
}
end
end
end
end
# The commit titles must be passed through Banzai before being shown.
# Doing this here in bulk allows significant database work to be skipped.
prerender_commits!
(
@logs
.
map
{
|
log
|
log
[
:commit
]
})
offset
=
(
@offset
+
@limit
)
offset
=
(
@offset
+
@limit
)
if
contents
.
size
>
offset
if
contents
.
size
>
offset
@more_log_url
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
||
''
,
offset:
offset
)
@more_log_url
=
logs_file_project_ref_path
(
@project
,
@ref
,
@path
||
''
,
offset:
offset
)
...
@@ -84,6 +89,11 @@ class Projects::RefsController < Projects::ApplicationController
...
@@ -84,6 +89,11 @@ class Projects::RefsController < Projects::ApplicationController
private
private
def
prerender_commits!
(
commits
)
renderer
=
Banzai
::
ObjectRenderer
.
new
(
user:
current_user
,
default_project:
@project
)
renderer
.
render
(
commits
,
:full_title
)
# modifies the commit objects inplace
end
def
validate_ref_id
def
validate_ref_id
return
not_found!
if
params
[
:id
].
present?
&&
params
[
:id
]
!~
Gitlab
::
PathRegex
.
git_reference_regex
return
not_found!
if
params
[
:id
].
present?
&&
params
[
:id
]
!~
Gitlab
::
PathRegex
.
git_reference_regex
end
end
...
...
app/models/commit.rb
View file @
d9833890
...
@@ -22,6 +22,7 @@ class Commit
...
@@ -22,6 +22,7 @@ class Commit
attr_accessor
:project
,
:author
attr_accessor
:project
,
:author
attr_accessor
:redacted_description_html
attr_accessor
:redacted_description_html
attr_accessor
:redacted_title_html
attr_accessor
:redacted_title_html
attr_accessor
:redacted_full_title_html
attr_reader
:gpg_commit
attr_reader
:gpg_commit
DIFF_SAFE_LINES
=
Gitlab
::
Git
::
DiffCollection
::
DEFAULT_LIMITS
[
:max_lines
]
DIFF_SAFE_LINES
=
Gitlab
::
Git
::
DiffCollection
::
DEFAULT_LIMITS
[
:max_lines
]
...
@@ -38,7 +39,12 @@ class Commit
...
@@ -38,7 +39,12 @@ class Commit
def
banzai_render_context
(
field
)
def
banzai_render_context
(
field
)
pipeline
=
field
==
:description
?
:commit_description
:
:single_line
pipeline
=
field
==
:description
?
:commit_description
:
:single_line
context
=
{
pipeline:
pipeline
,
project:
self
.
project
}
context
=
{
pipeline:
pipeline
,
project:
self
.
project
}
context
[
:author
]
=
self
.
author
if
self
.
author
# The author is only needed when rendering the description
if
field
==
:description
author
=
self
.
author
context
[
:author
]
=
author
if
author
end
context
context
end
end
...
...
app/views/projects/tree/_tree_commit_column.html.haml
View file @
d9833890
%span
.str-truncated
%span
.str-truncated
=
link_to_
markdown
commit
.
full_title
,
project_commit_path
(
@project
,
commit
.
id
),
class:
"tree-commit-link"
=
link_to_
html
commit
.
redacted_full_title_html
,
project_commit_path
(
@project
,
commit
.
id
),
class:
'tree-commit-link'
spec/features/projects/tree/tree_show_spec.rb
View file @
d9833890
...
@@ -4,16 +4,30 @@ describe 'Projects tree', :js do
...
@@ -4,16 +4,30 @@ describe 'Projects tree', :js do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
# This commit has a known state on the master branch of gitlab-test
let
(
:test_sha
)
{
'7975be0116940bf2ad4321f79d02a55c5f7779aa'
}
before
do
before
do
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
sign_in
(
user
)
sign_in
(
user
)
end
end
it
'renders tree table without errors'
do
it
'renders tree table without errors'
do
visit
project_tree_path
(
project
,
'master'
)
visit
project_tree_path
(
project
,
test_sha
)
wait_for_requests
expect
(
page
).
to
have_selector
(
'.tree-item'
)
expect
(
page
).
to
have_content
(
'add tests for .gitattributes custom highlighting'
)
expect
(
page
).
not_to
have_selector
(
'.flash-alert'
)
expect
(
page
).
not_to
have_selector
(
'.label-lfs'
,
text:
'LFS'
)
end
it
'renders tree table for a subtree without errors'
do
visit
project_tree_path
(
project
,
File
.
join
(
test_sha
,
'files'
))
wait_for_requests
wait_for_requests
expect
(
page
).
to
have_selector
(
'.tree-item'
)
expect
(
page
).
to
have_selector
(
'.tree-item'
)
expect
(
page
).
to
have_content
(
'add spaces in whitespace file'
)
expect
(
page
).
not_to
have_selector
(
'.label-lfs'
,
text:
'LFS'
)
expect
(
page
).
not_to
have_selector
(
'.label-lfs'
,
text:
'LFS'
)
expect
(
page
).
not_to
have_selector
(
'.flash-alert'
)
expect
(
page
).
not_to
have_selector
(
'.flash-alert'
)
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