Patch #37687

Retrieve attachments with a single query when rendering a journal

Added by Go MAEDA 18 days ago. Updated 14 days ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Performance
Target version:5.1.0

Description

The attached patch fixes N+1 queries in Journal#attachments.

Before:

D, [2022-09-19T17:11:55.977897 #39418] DEBUG -- :   Attachment Load (0.4ms)  SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" = ? LIMIT ?  [["id", 24], ["LIMIT", 1]]
D, [2022-09-19T17:11:55.978340 #39418] DEBUG -- :   ↳ app/models/journal.rb:145:in `block in attachments'
D, [2022-09-19T17:11:55.978659 #39418] DEBUG -- :   Attachment Load (0.1ms)  SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" = ? LIMIT ?  [["id", 25], ["LIMIT", 1]]
D, [2022-09-19T17:11:55.979025 #39418] DEBUG -- :   ↳ app/models/journal.rb:145:in `block in attachments'
D, [2022-09-19T17:11:55.979276 #39418] DEBUG -- :   Attachment Load (0.1ms)  SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" = ? LIMIT ?  [["id", 26], ["LIMIT", 1]]
D, [2022-09-19T17:11:55.979616 #39418] DEBUG -- :   ↳ app/models/journal.rb:145:in `block in attachments'

After:

D, [2022-09-19T17:35:55.808467 #41181] DEBUG -- :   Attachment Load (0.2ms)  SELECT "attachments".* FROM "attachments" WHERE "attachments"."id" IN (?, ?, ?)  [["id", 24], ["id", 25], ["id", 26]]
D, [2022-09-19T17:35:55.809074 #41181] DEBUG -- :   ↳ app/models/journal.rb:146:in `attachments'

reduce-extra-queries-in-journal-attachments.patch Magnifier (508 Bytes) Go MAEDA, 2022-09-19 10:44

0001-Get-attachments-with-single-query-when-rendering-a-j.patch Magnifier (840 Bytes) Go MAEDA, 2022-09-19 11:44

0002-Unify-duplicate-codes.patch Magnifier (1.44 KB) Go MAEDA, 2022-09-19 11:45

Associated revisions

Revision 21831
Added by Go MAEDA 14 days ago

Retrieve attachments with a single query when rendering a journal (#37687).

Patch by Go MAEDA.

Revision 21832
Added by Go MAEDA 14 days ago

Unify duplicate codes (#37687).

Patch by Go MAEDA.

History

#2 Updated by Go MAEDA 16 days ago

  • Target version set to 5.1.0

Setting the target version to 5.1.0.

#3 Updated by Go MAEDA 14 days ago

  • Subject changed from Get attachments with single query when rendering a journal to Retrieve attachments with single query when rendering a journal
  • Status changed from New to Closed
  • Assignee set to Go MAEDA

Committed the patch.

#4 Updated by Go MAEDA 14 days ago

  • Subject changed from Retrieve attachments with single query when rendering a journal to Retrieve attachments with a single query when rendering a journal

Also available in: Atom PDF