diff options
author | Nick Thomas <nick@gitlab.com> | 2018-09-04 13:51:02 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2018-09-06 12:28:56 +0100 |
commit | d9833890cca2c8fb388cc020f626f9d2c09871a4 (patch) | |
tree | cc82691a5d13ee2e3f67bd3d026631bae983435d /app/controllers/projects/refs_controller.rb | |
parent | 228d819b5761de1e2362952a9d0f08828c88424d (diff) | |
download | gitlab-ce-d9833890cca2c8fb388cc020f626f9d2c09871a4.tar.gz |
Bulk-render commit titles in the tree view to improve performance
Diffstat (limited to 'app/controllers/projects/refs_controller.rb')
-rw-r--r-- | app/controllers/projects/refs_controller.rb | 12 |
1 files changed, 11 insertions, 1 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 |