diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-08 19:13:52 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-15 16:30:34 +0300 |
commit | fce675d7fc7e408b3ec01a017a719c8cd036fa0d (patch) | |
tree | c6670a9f0126f15be1c951d288f7bb3539466a07 /lib/banzai/reference_parser/issue_parser.rb | |
parent | a4a85c269a4f3165914915ede4a9a7642057d105 (diff) |
Eager load project relations in IssueParser
By eager loading these associations we can greatly cut down the number
of SQL queries executed when processing documents with lots of
references, especially in cases where there are references belonging to
the same project.
Since these associations are so specific to the reference parsing
process and the permissions checking process that follows it I opted to
include them directly in IssueParser instead of using something like a
scope. Once we have a need for it we can move this code to a scope or
method.
Diffstat (limited to 'lib/banzai/reference_parser/issue_parser.rb')
-rw-r--r-- | lib/banzai/reference_parser/issue_parser.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/banzai/reference_parser/issue_parser.rb b/lib/banzai/reference_parser/issue_parser.rb index 24076e3d9ec..f306079d833 100644 --- a/lib/banzai/reference_parser/issue_parser.rb +++ b/lib/banzai/reference_parser/issue_parser.rb @@ -25,7 +25,21 @@ module Banzai def issues_for_nodes(nodes) @issues_for_nodes ||= grouped_objects_for_nodes( nodes, - Issue.all.includes(:author, :assignee, :project), + Issue.all.includes( + :author, + :assignee, + { + # These associations are primarily used for checking permissions. + # Eager loading these ensures we don't end up running dozens of + # queries in this process. + project: [ + { namespace: :owner }, + { group: [:owners, :group_members] }, + :invited_groups, + :project_members + ] + } + ), self.class.data_attribute ) end |