Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2016-07-29 01:53:56 +0300
committerDouwe Maan <douwe@gitlab.com>2016-07-29 01:53:56 +0300
commitb9b0c0283a001010370741c2683e2fe400bf7599 (patch)
treed049dbc0d499cc31ca83efb0a33e2eda71b7797f /app/models/legacy_diff_note.rb
parenta330b29b701b2de49206f864e654a01ad1a031c7 (diff)
parente4027e40707d8cde2c5326e99ae509b518a2190f (diff)
Merge branch 'fix/use-fewer-queries-for-mr-notes' into 'master'
Reduce number of queries made for merge_requests/:id/diffs ## What does this MR do? It reduces the number of DB queries made while processing and rendering MR notes. ## Are there points in the code the reviewer needs to double check? N/A ## Why was this MR needed? For `https://staging.gitlab.com/gitlab-org/gitlab-ce/merge_requests/3142/diffs.json`, for each note we make number of DB queries, almost all of them are handled by the AR caching layer, but they seem to add up a few seconds. Testing on staging, calling `merge_requests/3142/diffs.json` was reduced to ~5.5 seconds from ~8 seconds. ## What are the relevant issue numbers? N/A ## Screenshots (if relevant) N/A ## Does this MR meet the acceptance criteria? - [x] [CHANGELOG](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG) entry added - [ ] ~~[Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)~~ - [ ] ~~API support added~~ - ~~Tests~~ - [ ] ~~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) - [x] 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 !5551
Diffstat (limited to 'app/models/legacy_diff_note.rb')
-rw-r--r--app/models/legacy_diff_note.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb
index 04a651d50ab..865712268a0 100644
--- a/app/models/legacy_diff_note.rb
+++ b/app/models/legacy_diff_note.rb
@@ -25,6 +25,14 @@ class LegacyDiffNote < Note
@discussion_id ||= self.class.build_discussion_id(noteable_type, noteable_id || commit_id, line_code)
end
+ def project_repository
+ if RequestStore.active?
+ RequestStore.fetch("project:#{project_id}:repository") { self.project.repository }
+ else
+ self.project.repository
+ end
+ end
+
def diff_file_hash
line_code.split('_')[0] if line_code
end
@@ -34,7 +42,7 @@ class LegacyDiffNote < Note
end
def diff_file
- @diff_file ||= Gitlab::Diff::File.new(diff, repository: self.project.repository) if diff
+ @diff_file ||= Gitlab::Diff::File.new(diff, repository: project_repository) if diff
end
def diff_line