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
43b91111
Commit
43b91111
authored
Sep 04, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deduplicate commits before rendering them in RefsController#logs_tree
parent
d9833890
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
14 deletions
+19
-14
app/controllers/projects/refs_controller.rb
app/controllers/projects/refs_controller.rb
+19
-14
No files found.
app/controllers/projects/refs_controller.rb
View file @
43b91111
...
@@ -36,14 +36,9 @@ class Projects::RefsController < Projects::ApplicationController
...
@@ -36,14 +36,9 @@ class Projects::RefsController < Projects::ApplicationController
end
end
def
logs_tree
def
logs_tree
@offset
=
if
params
[
:offset
].
present?
@resolved_commits
||=
{}
params
[
:offset
].
to_i
else
0
end
@limit
=
25
@limit
=
25
@offset
=
params
[
:offset
].
to_i
@path
=
params
[
:path
]
@path
=
params
[
:path
]
contents
=
[]
contents
=
[]
...
@@ -57,19 +52,17 @@ class Projects::RefsController < Projects::ApplicationController
...
@@ -57,19 +52,17 @@ class Projects::RefsController < Projects::ApplicationController
file
=
@path
?
File
.
join
(
@path
,
content
.
name
)
:
content
.
name
file
=
@path
?
File
.
join
(
@path
,
content
.
name
)
:
content
.
name
last_commit
=
@repo
.
last_commit_for_path
(
@commit
.
id
,
file
)
last_commit
=
@repo
.
last_commit_for_path
(
@commit
.
id
,
file
)
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
,
# TODO: deduplicate commits so we don't render the same one multiple times
commit:
resolve_commit
(
last_commit
),
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.
prerender_commits!
# 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
...
@@ -89,9 +82,21 @@ class Projects::RefsController < Projects::ApplicationController
...
@@ -89,9 +82,21 @@ class Projects::RefsController < Projects::ApplicationController
private
private
def
prerender_commits!
(
commits
)
# Ensure that if multiple tree entries share the same last commit, they share
# a ::Commit instance. This prevents us from rendering the same commit title
# multiple times
def
resolve_commit
(
raw_commit
)
return
nil
unless
raw_commit
.
present?
@resolved_commits
[
raw_commit
.
id
]
||=
Commit
.
new
(
raw_commit
,
project
)
end
# The commit titles must be passed through Banzai before being shown.
# Doing this here in bulk allows significant database work to be skipped.
def
prerender_commits!
commits
=
@resolved_commits
.
values
renderer
=
Banzai
::
ObjectRenderer
.
new
(
user:
current_user
,
default_project:
@project
)
renderer
=
Banzai
::
ObjectRenderer
.
new
(
user:
current_user
,
default_project:
@project
)
renderer
.
render
(
commits
,
:full_title
)
# modifies the commit objects inplace
renderer
.
render
(
commits
,
:full_title
)
end
end
def
validate_ref_id
def
validate_ref_id
...
...
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