Reduce number of queries when calling GlobalMilestone#{labels,participants}

This commit is contained in:
Ahmad Sherif 2016-09-20 23:05:49 +02:00
parent ac3470280d
commit b8bfe50a50
2 changed files with 13 additions and 2 deletions

View File

@ -180,6 +180,7 @@ v 8.12.0 (unreleased)
- Clean environment variables when running git hooks - Clean environment variables when running git hooks
- Fix Import/Export issues importing protected branches and some specific models - Fix Import/Export issues importing protected branches and some specific models
- Fix non-master branch readme display in tree view - Fix non-master branch readme display in tree view
- Speed-up group milestones show page
- Add UX improvements for merge request version diffs - Add UX improvements for merge request version diffs
v 8.11.7 v 8.11.7

View File

@ -61,11 +61,11 @@ class GlobalMilestone
end end
def participants def participants
@participants ||= milestones.map(&:participants).flatten.compact.uniq @participants ||= milestones_relation.includes(:participants).map(&:participants).flatten.compact.uniq
end end
def labels def labels
@labels ||= GlobalLabel.build_collection(milestones.map(&:labels).flatten) @labels ||= GlobalLabel.build_collection(milestones_relation.includes(:labels).map(&:labels).flatten)
.sort_by!(&:title) .sort_by!(&:title)
end end
@ -89,4 +89,14 @@ class GlobalMilestone
end end
end 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 end