summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZ.J. van de Weg <zegerjan@gitlab.com>2016-06-13 14:31:47 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-06-23 20:59:34 +0200
commite7a27946ea6e165eac99098be6dbe8e6a408da4a (patch)
tree6355c581518a5c20fbeb9b27f51d6b9df03c06e0
parent2f161208d207efe2e1f890180c666bdde83ebcb3 (diff)
downloadgitlab-ce-e7a27946ea6e165eac99098be6dbe8e6a408da4a.tar.gz
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.
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--app/models/note.rb2
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