-
- Downloads
There was an error fetching the commit references. Please try again later.
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.
Showing
- app/models/concerns/avatarable.rb 47 additions, 0 deletionsapp/models/concerns/avatarable.rb
- app/models/concerns/with_uploads.rb 4 additions, 0 deletionsapp/models/concerns/with_uploads.rb
- app/models/note.rb 4 additions, 0 deletionsapp/models/note.rb
- app/models/personal_snippet.rb 1 addition, 0 deletionsapp/models/personal_snippet.rb
- app/uploaders/object_storage.rb 2 additions, 2 deletionsapp/uploaders/object_storage.rb
- changelogs/unreleased/fix-avatars-n-plus-one.yml 5 additions, 0 deletionschangelogs/unreleased/fix-avatars-n-plus-one.yml
- spec/uploaders/object_storage_spec.rb 22 additions, 0 deletionsspec/uploaders/object_storage_spec.rb
- spec/uploaders/workers/object_storage/background_move_worker_spec.rb 4 additions, 2 deletions...ers/workers/object_storage/background_move_worker_spec.rb
Please register or sign in to comment