diff options
author | Dan Rowden <hello@danrowden.com> | 2016-07-22 23:11:07 +0300 |
---|---|---|
committer | Alfredo Sumaran <alfredo@gitlab.com> | 2016-09-07 23:27:14 +0300 |
commit | 909deaa38a040777ec236d9365bc726c9de15194 (patch) | |
tree | 1b4d43e2617c67a6187f594287f051e4d4557e20 /app/helpers/milestones_helper.rb | |
parent | 431506bfd0c4b514d3b0aacc28e7a70d69679d50 (diff) |
Improved milestone counts with a single query
Diffstat (limited to 'app/helpers/milestones_helper.rb')
-rw-r--r-- | app/helpers/milestones_helper.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/app/helpers/milestones_helper.rb b/app/helpers/milestones_helper.rb index 9a71761a55c..797cbc341e3 100644 --- a/app/helpers/milestones_helper.rb +++ b/app/helpers/milestones_helper.rb @@ -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) |