Project

General

Profile

Actions

Patch #39847

closed

Cache the result of `Journal#attachments`

Added by Go MAEDA 5 months ago. Updated 4 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 #1

Updated by Go MAEDA 4 months ago

  • Target version set to 6.0.0
Actions #2

Updated by Go MAEDA 4 months ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch in r22581.

Actions

Also available in: Atom PDF