Actions
Feature #44407
openPreload the attachment authors when rendering a single issue in the REST API
Resolution:
Description
show.api.rsb renders the author of every attachment of the issue, causing an author lookup for each attachment.
Attachment Load (0.1ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."container_id" = ? AND "attachments"."container_type" = ? ORDER BY attachments.created_on ASC, attachments.id ASC [["container_id", 3], ["container_type", "Issue"]] ↳ app/views/issues/show.api.rsb:37 CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."type" IN (?, ?) AND "users"."id" = ? LIMIT ? [["type", "User"], ["type", "AnonymousUser"], ["id", 2], ["LIMIT", 1]] ↳ app/helpers/attachments_helper.rb:85:in 'AttachmentsHelper#render_api_attachment_attributes' CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."type" IN (?, ?) AND "users"."id" = ? LIMIT ? [["type", "User"], ["type", "AnonymousUser"], ["id", 2], ["LIMIT", 1]] ↳ app/helpers/attachments_helper.rb:85:in 'AttachmentsHelper#render_api_attachment_attributes' CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."type" IN (?, ?) AND "users"."id" = ? LIMIT ? [["type", "User"], ["type", "AnonymousUser"], ["id", 2], ["LIMIT", 1]] ↳ app/helpers/attachments_helper.rb:85:in 'AttachmentsHelper#render_api_attachment_attributes' CACHE User Load (0.0ms) SELECT "users".* FROM "users" WHERE "users"."type" IN (?, ?) AND "users"."id" = ? LIMIT ? [["type", "User"], ["type", "AnonymousUser"], ["id", 2], ["LIMIT", 1]] ↳ app/helpers/attachments_helper.rb:85:in 'AttachmentsHelper#render_api_attachment_attributes'
The patch loads all attachment authors with a single query. Requests without include=attachments are not affected.
Attachment Load (0.1ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."container_id" = ? AND "attachments"."container_type" = ? ORDER BY attachments.created_on ASC, attachments.id ASC [["container_id", 3], ["container_type", "Issue"]] ↳ app/views/issues/show.api.rsb:37 User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."type" IN (?, ?) AND "users"."id" = ? [["type", "User"], ["type", "AnonymousUser"], ["id", 2]] ↳ app/views/issues/show.api.rsb:37
Files
Actions