Search docs

Docs search
Back to Rule Catalog
AP-DQR-006Data / Query Risk

Large collection loaded then processed in memory

Flags query flows that load broad collections and filter or aggregate them in memory.

warningviolationNo auto-fix

How to fix

  1. Push filtering, projection, and aggregation into the query.
  2. Apply limits before loading records.
  3. Move large exports to explicit batch workflows.

What it means

A workflow appears to fetch more rows than it needs before applying filtering or aggregation.

Why it matters

In-memory processing can degrade latency and memory use for large tenants or repositories.

Common causes

  • Filtering was easier to express in application code.
  • Pagination was applied after fetching all rows.
  • A report path reused online request code.

Example bad pattern

findMany(...) loads all findings, then filters open findings in JavaScript.

Example good pattern

findMany({ where: { status: 'open' }, take: pageSize }).

Related files/config

  • apps/api/src
  • packages/db/prisma/schema.prisma

Related CLI commands

  • archpilot validate
  • archpilot validate --ci
AP-DQR-006 - Large collection loaded then processed in memory | ArchPilot Docs