Put 'hidden commits' logic in CommitsHelper

This commit is contained in:
Jacob Vosmaer 2016-03-04 15:45:58 +01:00
parent 5eeea4b7c6
commit f943156b5e
3 changed files with 23 additions and 12 deletions

View file

@ -211,4 +211,16 @@ module CommitsHelper
def clean(string) def clean(string)
Sanitize.clean(string, remove_contents: true) Sanitize.clean(string, remove_contents: true)
end 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 end

View file

@ -1,11 +1,14 @@
- commits, hidden = limited_commits(@commits, @project)
- commits = Commit.decorate(commits, @project)
%div.panel.panel-default %div.panel.panel-default
.panel-heading .panel-heading
Commits (#{@commits.count}) Commits (#{@commits.count})
- if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE - if hidden > 0
%ul.well-list %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 = render "projects/commits/inline_commit", commit: commit, project: @project
%li.warning-row.unstyled %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 - else
%ul.well-list= render Commit.decorate(@commits, @project), project: @project %ul.well-list= render commits, project: @project

View file

@ -1,11 +1,7 @@
- unless defined?(project) - unless defined?(project)
- project = @project - project = @project
- if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
- commits = @commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE) - commits, hidden = limited_commits(@commits)
- overflow = true
- else
- commits = @commits
- overflow = false
- commits.group_by { |c| c.committed_date.to_date }.sort.reverse.each do |day, commits| - commits.group_by { |c| c.committed_date.to_date }.sort.reverse.each do |day, commits|
.row.commits-row .row.commits-row
@ -20,6 +16,6 @@
= render commits, project: project = render commits, project: project
%hr.lists-separator %hr.lists-separator
- if overflow - if hidden > 0
.alert.alert-warning .alert.alert-warning
Not shown: #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} more commits Not shown: #{hidden} more commits