From f943156b5e4cf5e00ea5373de55deb993c72662d Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Fri, 4 Mar 2016 15:45:58 +0100 Subject: [PATCH] Put 'hidden commits' logic in CommitsHelper --- app/helpers/commits_helper.rb | 12 ++++++++++++ app/views/projects/commits/_commit_list.html.haml | 11 +++++++---- app/views/projects/commits/_commits.html.haml | 12 ++++-------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index a09e91578b6..4353ceaa757 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -211,4 +211,16 @@ module CommitsHelper def clean(string) Sanitize.clean(string, remove_contents: true) end + + def limited_commits(commits) + if commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE + # Not 100% sure we need to decorate but it is idempotent and not so slow + [ + commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE), + commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE + ] + else + [commits, 0] + end + end end diff --git a/app/views/projects/commits/_commit_list.html.haml b/app/views/projects/commits/_commit_list.html.haml index ce60fbdf032..5fe4d918833 100644 --- a/app/views/projects/commits/_commit_list.html.haml +++ b/app/views/projects/commits/_commit_list.html.haml @@ -1,11 +1,14 @@ +- commits, hidden = limited_commits(@commits, @project) +- commits = Commit.decorate(commits, @project) + %div.panel.panel-default .panel-heading Commits (#{@commits.count}) - - if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE + - if hidden > 0 %ul.well-list - - Commit.decorate(@commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE), @project).each do |commit| + - commits.each do |commit| = render "projects/commits/inline_commit", commit: commit, project: @project %li.warning-row.unstyled - other #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} commits hidden to prevent performance issues. + other #{hidden} commits hidden to prevent performance issues. - else - %ul.well-list= render Commit.decorate(@commits, @project), project: @project + %ul.well-list= render commits, project: @project diff --git a/app/views/projects/commits/_commits.html.haml b/app/views/projects/commits/_commits.html.haml index e708b2df540..998251094a4 100644 --- a/app/views/projects/commits/_commits.html.haml +++ b/app/views/projects/commits/_commits.html.haml @@ -1,11 +1,7 @@ - unless defined?(project) - project = @project -- if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE - - commits = @commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE) - - overflow = true -- else - - commits = @commits - - overflow = false + +- commits, hidden = limited_commits(@commits) - commits.group_by { |c| c.committed_date.to_date }.sort.reverse.each do |day, commits| .row.commits-row @@ -20,6 +16,6 @@ = render commits, project: project %hr.lists-separator -- if overflow +- if hidden > 0 .alert.alert-warning - Not shown: #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} more commits + Not shown: #{hidden} more commits