From d96585f5739f4cb83fd00fa402192a15d6958881 Mon Sep 17 00:00:00 2001 From: Eagllus Date: Tue, 16 Oct 2018 15:18:25 +0200 Subject: Moving state_count to Milestone model and related tests By moving and improving state_count the functions in GlobalMilestone are no longer used. --- app/models/milestone.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'app/models/milestone.rb') diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 892a680f221..9f2c4efaa96 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -170,6 +170,22 @@ class Milestone < ActiveRecord::Base sorted.with_order_id_desc end + def self.states_count(projects, groups = nil) + return STATE_COUNT_HASH unless projects || groups + + counts = Milestone + .for_projects_and_groups(projects&.map(&:id), groups&.map(&:id)) + .reorder(nil) + .group(:state) + .count + + { + opened: counts['active'] || 0, + closed: counts['closed'] || 0, + all: counts.values.sum + } + end + ## # Returns the String necessary to reference this Milestone in Markdown. Group # milestones only support name references, and do not support cross-project -- cgit v1.2.1