Project

General

Profile

Actions

Patch #39847

closed

Cache the result of `Journal#attachments`

Added by Go MAEDA 12 months ago. Updated 11 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Performance
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

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

cache-journal-attachments.patch (646 Bytes) cache-journal-attachments.patch Go MAEDA, 2023-12-14 12:09
Actions

Also available in: Atom PDF