Feature #44407
Updated by Go MAEDA 2 months ago
show.api.rsb renders the author of every attachment of the issue, causing an author lookup for each attachment. <pre> 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' </pre> The patch loads all attachment authors with a single query. Requests without @include=attachments@ are not affected. <pre> Attachment Load (0.1ms) SELECT "attachments".* FROM "attachments" WHERE "attachments"."container_id" = ? AND "attachments"."container_type" "att achments"."container_type" = ? ORDER BY attachments.created_on ASC, attachments.id ASC [["container_id", 3], ["container_type", ["cont ainer_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"], "U ser"], ["type", "AnonymousUser"], ["id", 2]] ↳ app/views/issues/show.api.rsb:37 </pre>