Commit e7a27946 authored by Z.J. van de Weg's avatar Z.J. van de Weg Committed by Paco Guzman

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.
parent 2f161208
......@@ -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,
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment