Skip to content

[HN-105] Unbounded findMany on providerUsageDaily with no default time window #468

Description

@ixjosemi

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions