Project

General

Profile

Actions

Patch #37687

closed

Retrieve attachments with a single query when rendering a journal

Added by Go MAEDA over 1 year ago. Updated over 1 year 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

Also available in: Atom PDF