summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-04-19 17:22:23 +0100
committerSean McGivern <sean@gitlab.com>2018-06-05 14:57:19 +0100
commit6ecf819f73ae28547e1b816780de0d85c3a653cf (patch)
treef81c50bb4e8a1984530e130e61871173fc73d4b9 /app/models/note.rb
parente11a1001dcdc1ea5c65845fb0897b861b5c0b92d (diff)
downloadgitlab-ce-6ecf819f73ae28547e1b816780de0d85c3a653cf.tar.gz
Fix an N+1 in avatar URLs
This is tricky: the query was being run in `ObjectStorage::Extension::RecordsUploads#retrieve_from_store!`, but we can't just add batch loading there, because the `#upload=` method there would use the result immediately, making the batch only have one item. Instead, we can pre-emptively add an item to the batch whenever an avatarable object is initialized, and then reuse that batch item in `#retrieve_from_store!`. However, this also has problems: 1. There is a lot of logic in `Avatarable#retrieve_upload_from_batch`. 2. Some of that logic constructs a 'fake' model for the batch key. This should be fine, because of ActiveRecord's override of `#==`, but it relies on that staying the same.
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 02f7a9b1e4f..41c04ae0571 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -435,6 +435,10 @@ class Note < ActiveRecord::Base
super.merge(noteable: noteable)
end
+ def retrieve_upload(_identifier, paths)
+ Upload.find_by(model: self, path: paths)
+ end
+
private
def keep_around_commit