diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-06 15:47:18 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2017-01-06 15:47:18 +0300 |
commit | f13c650c161b07bf8d6ad5db849fe9f442f6d0ac (patch) | |
tree | f8517deb61d8e485f8fbe1b6d87142f4c5b43567 /app/models/global_milestone.rb | |
parent | aec04a47c16665f1dfb1fb61647c3f78a4dde20f (diff) |
Speed up group milestone index by passing group_id to IssuesFinder
Diffstat (limited to 'app/models/global_milestone.rb')
-rw-r--r-- | app/models/global_milestone.rb | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb index a54e478f5f8..b991d78e27f 100644 --- a/app/models/global_milestone.rb +++ b/app/models/global_milestone.rb @@ -1,6 +1,8 @@ class GlobalMilestone include Milestoneish + EPOCH = DateTime.parse('1970-01-01') + attr_accessor :title, :milestones alias_attribute :name, :title @@ -8,13 +10,22 @@ class GlobalMilestone @first_milestone end - def self.build_collection(milestones) - milestones = milestones.group_by(&:title) + def self.build_collection(projects, params) + child_milestones = MilestonesFinder.new.execute(projects, params) - milestones.map do |title, milestones| - milestones_relation = Milestone.where(id: milestones.map(&:id)) + milestones = child_milestones.select(:id, :title).group_by(&:title).map do |title, grouped| + milestones_relation = Milestone.where(id: grouped.map(&:id)) new(title, milestones_relation) end + + milestones.sort_by { |milestone| milestone.due_date || EPOCH } + end + + def self.build(projects, title) + child_milestones = Milestone.of_projects(projects).where(title: title) + return if child_milestones.blank? + + new(title, child_milestones) end def initialize(title, milestones) |