summaryrefslogtreecommitdiff
path: root/app/models/global_milestone.rb
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-09-20 23:05:49 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-09-23 13:19:16 +0200
commitb8bfe50a5080909c7ba2b517d99d3c5f79d2a32f (patch)
treee1954df2cc9fb02e397ea8684dbe897fe5926343 /app/models/global_milestone.rb
parentac3470280dec5c9af43d9fa0da2ca47295c28d9a (diff)
downloadgitlab-ce-b8bfe50a5080909c7ba2b517d99d3c5f79d2a32f.tar.gz
Reduce number of queries when calling GlobalMilestone#{labels,participants}
Diffstat (limited to 'app/models/global_milestone.rb')
-rw-r--r--app/models/global_milestone.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/app/models/global_milestone.rb b/app/models/global_milestone.rb
index 81b7343d7ad..8f38a2b6254 100644
--- a/app/models/global_milestone.rb
+++ b/app/models/global_milestone.rb
@@ -61,11 +61,11 @@ class GlobalMilestone
end
def participants
- @participants ||= milestones.map(&:participants).flatten.compact.uniq
+ @participants ||= milestones_relation.includes(:participants).map(&:participants).flatten.compact.uniq
end
def labels
- @labels ||= GlobalLabel.build_collection(milestones.map(&:labels).flatten)
+ @labels ||= GlobalLabel.build_collection(milestones_relation.includes(:labels).map(&:labels).flatten)
.sort_by!(&:title)
end
@@ -89,4 +89,14 @@ class GlobalMilestone
end
end
end
+
+ private
+
+ def milestones_relation
+ @milestones_relation ||= if milestones.is_a?(ActiveRecord::Relation)
+ milestones
+ else
+ Milestone.where(id: milestones.map(&:id))
+ end
+ end
end