diff options
author | Sean McGivern <sean@gitlab.com> | 2018-08-16 14:08:00 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-08-21 14:40:44 +0300 |
commit | 22d8fbacaf153c0b29738e812a22764129483eee (patch) | |
tree | 4d9cbad46a5b44e3e71505dd6f0ab5bd66ff0bc8 /app/services/issues | |
parent | c73da6c1e73f04ece18b5fca5ccd67bf918682f8 (diff) |
Fix authors N+1 in Issues::ReferencedMergeRequestsService
`#referenced_merge_requests` preloaded too many associations. Award emoji, for
instance, are completely unnecessary here.
`#closed_by_merge_requests` had the opposite problem: `#all_references` needs
each item's author, and these weren't preloaded.
Diffstat (limited to 'app/services/issues')
-rw-r--r-- | app/services/issues/referenced_merge_requests_service.rb | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/app/services/issues/referenced_merge_requests_service.rb b/app/services/issues/referenced_merge_requests_service.rb index 9cce89636f5..40375a0c861 100644 --- a/app/services/issues/referenced_merge_requests_service.rb +++ b/app/services/issues/referenced_merge_requests_service.rb @@ -10,13 +10,7 @@ module Issues end def referenced_merge_requests(issue) - ext = issue.all_references(current_user) - - issue.notes_with_associations.each do |object| - object.all_references(current_user, extractor: ext) - end - - merge_requests = ext.merge_requests.sort_by(&:iid) + merge_requests = extract_merge_requests(issue, issue.notes) cross_project_filter = -> (merge_requests) do merge_requests.select { |mr| mr.target_project == project } @@ -34,13 +28,7 @@ module Issues def closed_by_merge_requests(issue) return [] unless issue.open? - ext = issue.all_references(current_user) - - issue.notes.system.each do |note| - note.all_references(current_user, extractor: ext) - end - - merge_requests = ext.merge_requests.select(&:open?) + merge_requests = extract_merge_requests(issue, issue.notes.system).select(&:open?) return [] if merge_requests.empty? @@ -50,6 +38,16 @@ module Issues private + def extract_merge_requests(issue, notes) + ext = issue.all_references(current_user) + + notes.includes(:author).each do |note| + note.all_references(current_user, extractor: ext) + end + + ext.merge_requests + end + def sort_by_iid(merge_requests) Gitlab::IssuableSorter.sort(project, merge_requests) { |mr| mr.iid.to_s } end |