diff options
author | Eagllus <rvanzon@gitlab.com> | 2018-10-16 15:18:25 +0200 |
---|---|---|
committer | Eagllus <rvanzon@gitlab.com> | 2018-10-17 15:42:10 +0200 |
commit | d96585f5739f4cb83fd00fa402192a15d6958881 (patch) | |
tree | 1c3cf954991fd0927a613ca0076a0d38ac439044 /app/models/global_milestone.rb | |
parent | 074fafe9e09935cd53cf286ad00b9d53240a9413 (diff) | |
download | gitlab-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/global_milestone.rb')
-rw-r--r-- | app/models/global_milestone.rb | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index d07ef43c97e..085ffd16c6a 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -34,66 +34,6 @@ class GlobalMilestone new(title, child_milestones) end - def self.states_count(projects, groups = nil) - legacy_group_milestones_count = legacy_group_milestone_states_count(projects) - group_milestones_count = groups_milestone_state_count(groups) - - legacy_group_milestones_count.merge(group_milestones_count) do |k, legacy_group_milestones_count, group_milestones_count| - legacy_group_milestones_count + group_milestones_count - end - end - - def self.groups_milestone_state_count(groups) - return STATE_COUNT_HASH unless groups - return self.group_milestones_states_count(groups) unless groups.respond_to?(:each) - - milestone_states = STATE_COUNT_HASH - - groups.each do |group| - group_milestones_count = self.group_milestones_states_count(group) - milestone_states = milestone_states.merge(group_milestones_count) do |k, milestone_state, group_milestones_count| - milestone_state + group_milestones_count - end - end - - milestone_states - end - - def self.group_milestones_states_count(group) - return STATE_COUNT_HASH unless group - - params = { group_ids: [group.id], state: 'all' } - - relation = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder - grouped_by_state = relation.reorder(nil).group(:state).count - - { - opened: grouped_by_state['active'] || 0, - closed: grouped_by_state['closed'] || 0, - all: grouped_by_state.values.sum - } - end - - # Counts the legacy group milestones which must be grouped by title - def self.legacy_group_milestone_states_count(projects) - return STATE_COUNT_HASH unless projects - - params = { project_ids: projects.map(&:id), state: 'all' } - - relation = MilestonesFinder.new(params).execute # rubocop: disable CodeReuse/Finder - project_milestones_by_state_and_title = relation.reorder(nil).group(:state, :title).count - - opened = count_by_state(project_milestones_by_state_and_title, 'active') - closed = count_by_state(project_milestones_by_state_and_title, 'closed') - all = project_milestones_by_state_and_title.map { |(_, title), _| title }.uniq.count - - { - opened: opened, - closed: closed, - all: all - } - end - def self.count_by_state(milestones_by_state_and_title, state) milestones_by_state_and_title.count do |(milestone_state, _), _| milestone_state == state |