summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2017-07-11 10:53:58 +0100
committerSean McGivern <sean@gitlab.com>2017-07-11 10:53:58 +0100
commitb35a7a386af442a75f35dd1d4ec1a3f5b83e7352 (patch)
tree843b0adae11ced6103ddb85812503db912f073e2
parent25d241ae97e22159bf71caa5553eb192fdb6d4c0 (diff)
downloadgitlab-ce-fix-n-plus-one-in-url-builder.tar.gz
Don't reload ActiveRecord objects when building note URLsfix-n-plus-one-in-url-builder
When we build a note URL, and we have the note loaded already, there are two cases: 1. The `noteable` is already loaded. In that case, this is faster as it doesn't build a new AR object from the query. 2. The `noteable` is not already loaded. In that case, this change is no worse than the previous code.
-rw-r--r--changelogs/unreleased/fix-n-plus-one-in-url-builder.yml4
-rw-r--r--lib/gitlab/url_builder.rb8
2 files changed, 7 insertions, 5 deletions
diff --git a/changelogs/unreleased/fix-n-plus-one-in-url-builder.yml b/changelogs/unreleased/fix-n-plus-one-in-url-builder.yml
new file mode 100644
index 00000000000..5781316cfd9
--- /dev/null
+++ b/changelogs/unreleased/fix-n-plus-one-in-url-builder.yml
@@ -0,0 +1,4 @@
+---
+title: Improve issue rendering performance with lots of notes from other users
+merge_request:
+author:
diff --git a/lib/gitlab/url_builder.rb b/lib/gitlab/url_builder.rb
index 35792d2d67f..824e2d7251f 100644
--- a/lib/gitlab/url_builder.rb
+++ b/lib/gitlab/url_builder.rb
@@ -52,15 +52,13 @@ module Gitlab
commit_url(id: object.commit_id, anchor: dom_id(object))
elsif object.for_issue?
- issue = Issue.find(object.noteable_id)
- issue_url(issue, anchor: dom_id(object))
+ issue_url(object.noteable, anchor: dom_id(object))
elsif object.for_merge_request?
- merge_request = MergeRequest.find(object.noteable_id)
- merge_request_url(merge_request, anchor: dom_id(object))
+ merge_request_url(object.noteable, anchor: dom_id(object))
elsif object.for_snippet?
- snippet = Snippet.find(object.noteable_id)
+ snippet = object.noteable
if snippet.is_a?(PersonalSnippet)
snippet_url(snippet, anchor: dom_id(object))