Skip to content

Add database indexes for settlement and anchor status queries #200

Description

@Cjay-Cyber-2

Description

Add and validate Prisma indexes that support the high-frequency settlement and SEP-24 worker queries. This keeps status polling and background processing responsive as the number of groups, expenses, and transactions grows.

Context & Requirements

The API uses Prisma and a dedicated worker at src/worker/index.ts. Worker queries commonly need to find records by processing status, retry eligibility, update time, or group ownership. Without suitable composite indexes, those queries can scan large tables and delay all jobs. Indexes must reflect the actual filters and ordering in the code, not be added generically.

Avoid changing application semantics or removing existing indexes. Consider write overhead and index selectivity, and use a migration that can be deployed safely with the repository's Prisma workflow. The change should also identify queries that need a bounded limit so an index does not mask unbounded work.

Acceptance Criteria

  • The Prisma schema contains indexes for the settlement and anchor query paths used by request handlers and src/worker/index.ts.
  • Composite index column order matches the main filtering and ordering patterns.
  • A migration is included and can be applied with the repository's documented Prisma commands.
  • Worker queries use bounded batches and take advantage of the indexed fields.
  • No existing authorization, status, or retry behavior changes as a result of the optimization.
  • The PR includes before-and-after query timing or query-plan evidence using representative data.

Implementation Guidance

Inspect the Prisma schema, migrations, and all settlement or SEP-24 queries under src. Trace the worker selection logic from src/worker/index.ts to the relevant service methods before selecting indexes. Prefer the smallest set of composite indexes that covers real filters and sort order. If the database provider has limitations on online index creation, document the deployment consideration rather than hiding it in application code.

Testing & Validation

Add or update repository tests to confirm worker selection and pagination behavior remain correct. Seed representative records using the existing prisma/seed.ts pattern or a test fixture, then capture query plans or timing before and after the migration. Run npm run prisma:generate, npm run build, npm test, and npm run lint.

Submission Guidelines

Assignment is required before starting. Open one PR that includes Closes #<issue-number>, includes the Prisma migration, and explains the workload and query evidence behind each index.


Wave complexity: Medium

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions