Skip to content

Audit D1 token joins across read endpoints #53

@olearycrew

Description

@olearycrew

Summary

Several read endpoints still join tokens even when the request does not filter by verified/claimed status and does not return token-derived fields. These are related to the D1 read disparity addressed for /api/submissions, but broadening the current PR would increase regression risk across leaderboard/model/provider response shapes.

Candidate endpoints

  • /api/model-submissions: best-row and list queries join tokens even when verified=false and no claimed data is returned.
  • /api/models, /api/providers, /api/providers/:provider/models: joins appear necessary only for verified=true.
  • /api/leaderboard: aggregate query and totalModels paths should be audited for token joins that are unrelated to verified filtering.

Acceptance criteria

  • Add representative parity tests for each affected endpoint and query shape.
  • Skip tokens joins whenever no verified predicate or token-derived projection is required.
  • Add SQL-shape regression tests to prevent unconditional joins from returning.
  • Include lightweight row-read or query-plan assertions where practical.

Notes

The /api/submissions pagination COUNT hot path is intentionally handled separately in the current fix branch to keep the production change minimal and low risk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions