Skip to content

perf(invoices): covering indexes for list query (closes #2265) - #2324

Merged
github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2265-covering-indexes
Nov 24, 2026
Merged

github-actions[bot] merged 1 commit into
Smartdevs17:mainfrom
IVANLI2412:fix/issue-2265-covering-indexes

Conversation

@IVANLI2412

Copy link
Copy Markdown
Contributor

Closes #2265

Summary

Adds covering indexes for the invoices list query plus a pure, testable query contract that keeps the endpoint aligned with them. Both technical-scope files were missing upstream and are created fresh; only those files and their unit tests are touched.

  • backend/prisma/schema.prisma — new focused Prisma description of the invoices read model. The baseline single-column indexes are preserved and three covering indexes are added, each carrying the full GET /invoices projection plus the ordered created_at key:
    • idx_invoices_list_recent_covering — (created_at DESC, invoice_number, customer_name, customer_email, status, total, currency, invoice_date, due_date) for the unfiltered default page.
    • idx_invoices_list_customer_covering — (customer_email, created_at DESC, ...) for the customer_email filter and the combined customer+status page.
    • idx_invoices_list_status_covering — (status, created_at DESC, ...) for the status-only filter.
      Every index is index-only for the eight-column projection: equality on the leading key, ORDER BY created_at DESC satisfied by the key order, no Sort node and no heap fetch for projected columns.
  • backend/src/services/invoices.ts — zero-dependency, side-effect-free module: canonical index definitions mirroring schema.prisma, the fixed projection / filter columns / sort term, selectInvoiceListIndex, checkInvoiceListCoverage (rejects projection drift, sort mismatches, uncovered columns and out-of-range limits), and buildInvoiceListQuery (parameterized index-aligned SQL, clamped limit, no functions on indexed columns). An optional onIndexSelected hook emits the chosen index for metrics/logs, and toPrismaIndexDeclaration renders the exact @@index([...]) declarations so schema/service drift is pinned by tests.
  • Tests — backend/src/services/__tests__/invoices.test.ts pins the projection, index selection for all four filter shapes, coverage-validation failure modes, exact generated SQL/params, limit clamping, stable error codes and the observability hook.

No new dependencies, no binaries, no new markdown/JSON files (documentation is JSDoc in source). prisma.config.js still points at db/migrations/schema.prisma, so runtime Prisma generation is unaffected.

Verification

  • Node 26 native type-stripping harness importing the real .ts sources through pathToFileURL with explicit .ts extensions: 26 passed / 0 failed, 113 assertions evaluated (including schema declarations matching the service-generated @@index strings and schema bracket / index-count balance).
  • Secret scan python tools/check_secrets.py: [OK], SECRETS_EXIT=0.
  • git push fork fix/issue-2265-covering-indexes: exit 0 (no force, no push to fork main).

Payouts

  • Base Mainnet (USDC/ETH): 0xC5dD2Ea54FF138bb3f71D3466092eA31eF115868
  • Solana (USDC/SOL): DN3pfYEvdkoTBP4oaEVvemsr98fZPhDSAbfVfmewRGQ5
  • PayPal: ivanzenteno3@gmail.com

@github-actions
github-actions Bot merged commit 3385040 into Smartdevs17:main Nov 24, 2026
6 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch invoice list queries to covering indexes with narrowed projection

1 participant