Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-09-04 15:51:02 +0300
committerNick Thomas <nick@gitlab.com>2018-09-06 14:28:56 +0300
commitd9833890cca2c8fb388cc020f626f9d2c09871a4 (patch)
treecc82691a5d13ee2e3f67bd3d026631bae983435d /app
parent228d819b5761de1e2362952a9d0f08828c88424d (diff)
Bulk-render commit titles in the tree view to improve performance
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/refs_controller.rb12
-rw-r--r--app/models/commit.rb8
-rw-r--r--app/views/projects/tree/_tree_commit_column.html.haml2
3 files changed, 19 insertions, 3 deletions
diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb
index 48a09e1ddb8..4a4e9ec1d7d 100644
--- a/app/controllers/projects/refs_controller.rb
+++ b/app/controllers/projects/refs_controller.rb
@@ -59,13 +59,18 @@ class Projects::RefsController < Projects::ApplicationController
commit_path = project_commit_path(@project, last_commit) if last_commit
{
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,
commit_path: commit_path
}
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)
if contents.size > offset
@more_log_url = logs_file_project_ref_path(@project, @ref, @path || '', offset: offset)
@@ -84,6 +89,11 @@ class Projects::RefsController < Projects::ApplicationController
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
return not_found! if params[:id].present? && params[:id] !~ Gitlab::PathRegex.git_reference_regex
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 594972ad344..c993f3ed507 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -22,6 +22,7 @@ class Commit
attr_accessor :project, :author
attr_accessor :redacted_description_html
attr_accessor :redacted_title_html
+ attr_accessor :redacted_full_title_html
attr_reader :gpg_commit
DIFF_SAFE_LINES = Gitlab::Git::DiffCollection::DEFAULT_LIMITS[:max_lines]
@@ -38,7 +39,12 @@ class Commit
def banzai_render_context(field)
pipeline = field == :description ? :commit_description : :single_line
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
end
diff --git a/app/views/projects/tree/_tree_commit_column.html.haml b/app/views/projects/tree/_tree_commit_column.html.haml
index abb3e918e87..406dccb74fb 100644
--- a/app/views/projects/tree/_tree_commit_column.html.haml
+++ b/app/views/projects/tree/_tree_commit_column.html.haml
@@ -1,2 +1,2 @@
%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'