summaryrefslogtreecommitdiff
path: root/app/models/milestone.rb
diff options
context:
space:
mode:
authorEagllus <rvanzon@gitlab.com>2018-10-16 15:18:25 +0200
committerEagllus <rvanzon@gitlab.com>2018-10-17 15:42:10 +0200
commitd96585f5739f4cb83fd00fa402192a15d6958881 (patch)
tree1c3cf954991fd0927a613ca0076a0d38ac439044 /app/models/milestone.rb
parent074fafe9e09935cd53cf286ad00b9d53240a9413 (diff)
downloadgitlab-ce-d96585f5739f4cb83fd00fa402192a15d6958881.tar.gz
Moving state_count to Milestone model and related tests
By moving and improving state_count the functions in GlobalMilestone are no longer used.
Diffstat (limited to 'app/models/milestone.rb')
-rw-r--r--app/models/milestone.rb16
1 files changed, 16 insertions, 0 deletions
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