From e7a27946ea6e165eac99098be6dbe8e6a408da4a Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Mon, 13 Jun 2016 14:31:47 +0200 Subject: [PATCH] Eager load award emoji on notes This commit eager loads the award emoji on both the issues and the MRs. When loading an issue with 108 comments this reduces the query count by 327 queries. On a merge request with the same amount of comments this saves 148 queries. The large difference is not clear to me at this point and the total query count is still huge with 387 and 1034 respectively. The biggest problem however, remains the calculation of participants. --- app/models/merge_request.rb | 2 +- app/models/note.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 36bc98bdb1e..478827794ed 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -309,7 +309,7 @@ class MergeRequest < ActiveRecord::Base commits_for_notes_limit = 100 commit_ids = commits.last(commits_for_notes_limit).map(&:id) - Note.where( + Note.includes(:award_emoji).where( "(project_id = :target_project_id AND noteable_type = 'MergeRequest' AND noteable_id = :mr_id) OR" + "((project_id = :source_project_id OR project_id = :target_project_id) AND noteable_type = 'Commit' AND commit_id IN (:commit_ids))", mr_id: id, diff --git a/app/models/note.rb b/app/models/note.rb index 8d164647550..4bc9d1a92f8 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -54,7 +54,7 @@ class Note < ActiveRecord::Base scope :non_diff_notes, ->{ where(type: ['Note', nil]) } scope :with_associations, -> do - includes(:author, :noteable, :updated_by, + includes(:author, :noteable, :updated_by, :award_emoji, project: [:project_members, { group: [:group_members] }]) end -- GitLab