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:
parent
a4a85c269a
commit
fce675d7fc
|
@ -93,6 +93,7 @@ v 8.9.0 (unreleased)
|
||||||
- Hide global side navigation by default
|
- Hide global side navigation by default
|
||||||
- Remove tanuki logo from side navigation; center on top nav
|
- Remove tanuki logo from side navigation; center on top nav
|
||||||
- Include user relationships when retrieving award_emoji
|
- 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)
|
v 8.8.5 (unreleased)
|
||||||
- Ensure branch cleanup regardless of whether the GitHub import process succeeds
|
- Ensure branch cleanup regardless of whether the GitHub import process succeeds
|
||||||
|
|
|
@ -25,7 +25,21 @@ module Banzai
|
||||||
def issues_for_nodes(nodes)
|
def issues_for_nodes(nodes)
|
||||||
@issues_for_nodes ||= grouped_objects_for_nodes(
|
@issues_for_nodes ||= grouped_objects_for_nodes(
|
||||||
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
|
self.class.data_attribute
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue