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.
This commit is contained in:
Yorick Peterse 2016-06-08 18:13:52 +02:00
parent a4a85c269a
commit fce675d7fc
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
2 changed files with 16 additions and 1 deletions

View File

@ -93,6 +93,7 @@ v 8.9.0 (unreleased)
- Hide global side navigation by default
- Remove tanuki logo from side navigation; center on top nav
- Include user relationships when retrieving award_emoji
- Various associations are now eager loaded when parsing issue references to reduce the number of queries executed
v 8.8.5 (unreleased)
- Ensure branch cleanup regardless of whether the GitHub import process succeeds

View File

@ -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