Commit 8bfbafbb authored by Douwe Maan's avatar Douwe Maan

Merge branch 'eager-loading-issue-parser' into 'master'

Eager load project relations in IssueParser

## What does this MR do?

This changes the ReferenceParser class to eager load various associations. This in turn results in the permissions checking code (e.g. the `Ability` model) to _not_ run dozens if not hundreds of extra SQL queries depending on the amount of references involved (in a single document).

## Are there points in the code the reviewer needs to double check?

No.

## Why was this MR needed?

In !4410 it was revealed a _lot_ of a queries came from the `Ability` model and the code it would call. In many cases this was because the code would simply get a project, then get the owners; or get a group, then get some association of that. Eager loading these associations is a fairly simple solution and greatly cuts down the number of queries.

## What are the relevant issue numbers?

None.

## Does this MR meet the acceptance criteria?

- [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added
- [x] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~
- [x] ~~API support added~~
- [ ] Tests
  - [x] ~~Added for this feature/bug~~
  - [ ] All builds are passing
- [x] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if you do - rebase it please)
- [x] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

See merge request !4675
parents a95f8b9a fce675d7
...@@ -95,6 +95,7 @@ v 8.9.0 (unreleased) ...@@ -95,6 +95,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 ...@@ -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
......
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