diff options
author | Sean McGivern <sean@gitlab.com> | 2017-07-11 10:53:58 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2017-07-11 13:02:55 +0100 |
commit | 222a6b4680b19f578b42b32d908a1d3cb8e343f7 (patch) | |
tree | 9c0e8b251efde7e67a3a500a4b2cecae1cd496f0 /lib | |
parent | c17b1d5f5651b6f73b8c999bb6a5376e31a7d30d (diff) | |
download | gitlab-ce-222a6b4680b19f578b42b32d908a1d3cb8e343f7.tar.gz |
Don't reload ActiveRecord objects when building note URLs
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.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/url_builder.rb | 8 |
1 files changed, 3 insertions, 5 deletions
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)) |