Actions
Patch #39847
closedCache the result of `Journal#attachments`
Description
When rendering an issue history, Journal#attachments
is called twice while rendering a single journal.
We can improve efficiency by caching the result of the method. With caching, unnecessary iterations over details and calls to Attachment.where can be reduced.
Before:
Attachment Load (0.4ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" IN ($1, $2) [["id", 39], ["id", 38]] ↳ app/models/journal.rb:146:in `sort_by' CACHE Attachment Load (0.0ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" IN ($1, $2) [["id", 39], ["id", 38]] ↳ app/models/journal.rb:146:in `sort_by'
After:
Attachment Load (0.4ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" IN ($1, $2) [["id", 39], ["id", 38]] ↳ app/models/journal.rb:147:in `sort_by'
Files
Actions