Problem
Three providerUsageDaily.findMany calls run with no take:
const rows = await prisma.providerUsageDaily.findMany({
where: buildDailyWhere(filters),
})
And buildDailyWhere emits no bucketDate clause at all when neither from nor to is supplied, so the unfiltered call is a full table scan returning every row ever written.
Location
apps/web/src/lib/services/provider-usage.ts:204-205, :227-228, :254-255; buildDailyWhere at :104
Impact
providerUsageDaily grows by one row per provider per day, forever, and is never pruned. The query cost therefore increases monotonically with the age of the deployment, and the whole result set is materialised in Node memory before aggregation.
Being explicit about severity: this does not hurt today — the table is young and the row count is small. It is filed because unlike most latent issues this one degrades with certainty rather than conditionally, and the fix is cheap now and annoying later.
Suggested fix
Add a take, and make buildDailyWhere fall back to a default time window (e.g. last 90 days) when no from/to is provided, so the unfiltered path is bounded by construction rather than by the caller remembering to pass filters.
Source: independent verification pass (Claude Opus 5). Not part of the HN-001..HN-063 batch.
Problem
Three
providerUsageDaily.findManycalls run with notake:And
buildDailyWhereemits nobucketDateclause at all when neitherfromnortois supplied, so the unfiltered call is a full table scan returning every row ever written.Location
apps/web/src/lib/services/provider-usage.ts:204-205,:227-228,:254-255;buildDailyWhereat:104Impact
providerUsageDailygrows by one row per provider per day, forever, and is never pruned. The query cost therefore increases monotonically with the age of the deployment, and the whole result set is materialised in Node memory before aggregation.Being explicit about severity: this does not hurt today — the table is young and the row count is small. It is filed because unlike most latent issues this one degrades with certainty rather than conditionally, and the fix is cheap now and annoying later.
Suggested fix
Add a
take, and makebuildDailyWherefall back to a default time window (e.g. last 90 days) when nofrom/tois provided, so the unfiltered path is bounded by construction rather than by the caller remembering to pass filters.Source: independent verification pass (Claude Opus 5). Not part of the HN-001..HN-063 batch.