Please sign in to comment.
Remove n+1 select when showing lists of publications.
Two things were causing the n+1. First, to determine the background colour for each listed publication, the 'root' document organisation was chosen. With the many-to-many relationship between organisations this was expensive. I've changed this to no longer search for the root; instead the first organisation is chosen. This means that documents belonging to 'child' organisations may not have a background colour yet, but these can easily be added to the css if required. There was no guarantee that even 'root' organisations had colours assigned, and most publications belong to 'root' organisation, so this is only a minor regression. The second change is in the way the thumbnail image is chosen. It previously used a special scope to find the first PDF attachment and using that. Now this filtering is done in ruby, allowing us to `include` the attachments association (and thereby avoid the n+1).
- Loading branch information...
Showing with 27 additions and 31 deletions.
- +1 −1 app/controllers/publications_controller.rb
- +2 −2 app/helpers/document_helper.rb
- +0 −2 app/models/attachment.rb
- +1 −1 app/models/document/attachable.rb
- +12 −11 test/functional/publications_controller_test.rb
- +11 −0 test/support/controller_test_helpers.rb
- +0 −7 test/unit/attachment_test.rb
- +0 −7 test/unit/helpers/document_helper_test.rb