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
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-09-04 18:52:00 +0300
committerNick Thomas <nick@gitlab.com>2018-09-06 14:28:56 +0300
commit43b91111d698c97c9d07617bb36db8d92bb9a0d9 (patch)
tree2318c17db4775bfe9ddbbe86a360f9a416029be0 /app/controllers/projects/refs_controller.rb
parentd9833890cca2c8fb388cc020f626f9d2c09871a4 (diff)
Deduplicate commits before rendering them in RefsController#logs_tree
Diffstat (limited to 'app/controllers/projects/refs_controller.rb')
-rw-r--r--app/controllers/projects/refs_controller.rb33
1 files changed, 19 insertions, 14 deletions
diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb
index 4a4e9ec1d7d..97231b09c05 100644
--- a/app/controllers/projects/refs_controller.rb
+++ b/app/controllers/projects/refs_controller.rb
@@ -36,14 +36,9 @@ class Projects::RefsController < Projects::ApplicationController
end
def logs_tree
- @offset = if params[:offset].present?
- params[:offset].to_i
- else
- 0
- end
-
+ @resolved_commits ||= {}
@limit = 25
-
+ @offset = params[:offset].to_i
@path = params[:path]
contents = []
@@ -57,19 +52,17 @@ class Projects::RefsController < Projects::ApplicationController
file = @path ? File.join(@path, content.name) : content.name
last_commit = @repo.last_commit_for_path(@commit.id, file)
commit_path = project_commit_path(@project, last_commit) if last_commit
+
{
file_name: content.name,
- # TODO: deduplicate commits so we don't render the same one multiple times
- commit: (Commit.new(last_commit, project) if last_commit),
+ commit: resolve_commit(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] })
+ prerender_commits!
offset = (@offset + @limit)
if contents.size > offset
@@ -89,9 +82,21 @@ class Projects::RefsController < Projects::ApplicationController
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.render(commits, :full_title) # modifies the commit objects inplace
+ renderer.render(commits, :full_title)
end
def validate_ref_id