Skip to content

perf(accounts): N+1 queries on AccountsController#show activity feed (transfer/category/split-parent) #2462

Description

@JSONbored

AccountsController#show renders the paginated activity feed with several N+1 query clusters that Sentry has flagged across 60–150 unique users:

  • SURE-APP-PN / SURE-APP-XE / SURE-APP-26transfer_as_inflow / transfer_as_outflow (and category) loaded per transaction row of the page (≈40 rows × multiple queries).
  • SURE-APP-X3 / SURE-APP-X6 — slow-DB reports on the same action.
  • A split_parent? N+1 — entry.split_parent? calls child_entries.exists? per entry because the view's @split_parent_entry_ids guard is never set by this action. TransactionsController#index already sets it; AccountsController#show is the only caller that doesn't.

Scope: in AccountsController#show, after pagination, preload the page transactions' transfer_as_inflow/transfer_as_outflow/category/merchant associations and set @split_parent_entry_ids via a single batch pluck over the page's entry IDs — eliminating the per-row queries. Page-scoped by design (only the rendered page resolves its split parents).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions