Project

General

Profile

Actions

Patch #37687

closed

Retrieve attachments with a single query when rendering a journal

Added by Go MAEDA about 2 years ago. Updated about 2 years ago.

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

0%

Estimated time:

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'


Files

Actions #2

Updated by Go MAEDA about 2 years ago

  • Target version set to 5.1.0

Setting the target version to 5.1.0.

Actions #3

Updated by Go MAEDA about 2 years 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.

Actions #4

Updated by Go MAEDA about 2 years ago

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

Also available in: Atom PDF