Repository navigation
perf(invoices): covering indexes for list query (closes #2265) - #2324
Merged
github-actions[bot] merged 1 commit intoNov 24, 2026
Merged
github-actions[bot] merged 1 commit into
github-actions[bot] merged 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 theinvoicesread model. The baseline single-column indexes are preserved and three covering indexes are added, each carrying the full GET /invoices projection plus the orderedcreated_atkey: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 DESCsatisfied 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 mirroringschema.prisma, the fixed projection / filter columns / sort term,selectInvoiceListIndex,checkInvoiceListCoverage(rejects projection drift, sort mismatches, uncovered columns and out-of-range limits), andbuildInvoiceListQuery(parameterized index-aligned SQL, clamped limit, no functions on indexed columns). An optionalonIndexSelectedhook emits the chosen index for metrics/logs, andtoPrismaIndexDeclarationrenders the exact@@index([...])declarations so schema/service drift is pinned by tests.backend/src/services/__tests__/invoices.test.tspins 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.jsstill points atdb/migrations/schema.prisma, so runtime Prisma generation is unaffected.Verification
.tssources throughpathToFileURLwith explicit.tsextensions: 26 passed / 0 failed, 113 assertions evaluated (including schema declarations matching the service-generated@@indexstrings and schema bracket / index-count balance).python tools/check_secrets.py:[OK], SECRETS_EXIT=0.git push fork fix/issue-2265-covering-indexes: exit 0 (no force, no push to forkmain).Payouts