diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-06-15 14:00:31 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-06-15 14:00:31 +0000 |
commit | 8bfbafbb6b2166d3709187cf6b1cb7ff5f627d52 (patch) | |
tree | 6f2a78770a7ebc32511a9084823730463c5fc771 | |
parent | a95f8b9a82e79781dc99ff36d6ab5f9ba293ae52 (diff) | |
parent | fce675d7fc7e408b3ec01a017a719c8cd036fa0d (diff) | |
download | gitlab-ce-8bfbafbb6b2166d3709187cf6b1cb7ff5f627d52.tar.gz |
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
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | lib/banzai/reference_parser/issue_parser.rb | 16 |
2 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG index 3674cd6055b..07d2d950bbc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -95,6 +95,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 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 |