Improved milestone counts with a single query
This commit is contained in:
parent
431506bfd0
commit
909deaa38a
2 changed files with 15 additions and 14 deletions
|
@ -35,17 +35,16 @@ module MilestonesHelper
|
|||
milestone.issues.with_label(label.title).send(state).size
|
||||
end
|
||||
|
||||
def milestone_count_by_state(project, state)
|
||||
if project.nil?
|
||||
nil
|
||||
else
|
||||
case state
|
||||
when 'all' then @project.milestones.size
|
||||
when 'closed' then @project.milestones.closed.size
|
||||
when 'opened' then @project.milestones.active.size
|
||||
else nil
|
||||
end
|
||||
end
|
||||
# Returns count of milestones for different states
|
||||
# Uses explicit hash keys as the 'opened' state URL params differs from the db value
|
||||
# and we need to add the total
|
||||
def milestone_counts(project:)
|
||||
counts = @project.milestones.reorder(nil).group(:state).count()
|
||||
{
|
||||
'opened' => counts['active'],
|
||||
'closed' => counts['closed'],
|
||||
'all' => counts['active'] + counts['closed']
|
||||
}
|
||||
end
|
||||
|
||||
def milestone_progress_bar(milestone)
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
- counts = milestone_counts(project: @project)
|
||||
|
||||
%ul.nav-links
|
||||
%li{class: ("active" if params[:state].blank? || params[:state] == 'opened')}
|
||||
= link_to milestones_filter_path(state: 'opened') do
|
||||
Open
|
||||
%span.badge #{milestone_count_by_state(@project, 'opened')}
|
||||
%span.badge #{counts['opened']}
|
||||
%li{class: ("active" if params[:state] == 'closed')}
|
||||
= link_to milestones_filter_path(state: 'closed') do
|
||||
Closed
|
||||
%span.badge #{milestone_count_by_state(@project, 'closed')}
|
||||
%span.badge #{counts['closed']}
|
||||
%li{class: ("active" if params[:state] == 'all')}
|
||||
= link_to milestones_filter_path(state: 'all') do
|
||||
All
|
||||
%span.badge #{milestone_count_by_state(@project, 'all')}
|
||||
%span.badge #{counts['all']}
|
||||
|
|
Loading…
Reference in a new issue