fix(#768): eliminate redundant DB reads in transaction-documents.service#857
Open
jethrojohn739-max wants to merge 1 commit into
Open
Conversation
…ments.service
- Consolidate sequential ensureTransactionExists + document queries into
batched ([tx select, doc findFirst]) round-trips for
findOne, addVersion, getVersions, and remove — reducing reads per call
from 2 to 1 batched operation.
- list: batches transaction access-select + document.findMany in a single
batch (was 2 sequential queries).
- getVersions: was 3 sequential queries (tx check, doc existence, versions
findMany with uploadedBy); now 1 batched round-trip with versions and
uploader embedded via include.
- Use select: { id, buyerId, sellerId } on transaction queries to fetch
only the access-control fields needed, reducing data transfer.
- Remove @ts-nocheck from service and dto; add proper TypeScript types
(TxAccess, DocumentWithVersions, VersionWithUploader, DocumentTypeValue).
- Replace as any casts with correct Prisma-typed field assignments.
|
@jethrojohn739-max Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Summary
Closes #768 [E7] — audit and eliminate redundant DB reads in
transaction-documents.service.ts.Problem
Every public method in
TransactionDocumentsServicefollowed a two-query sequential pattern:ensureTransactionExists(transactionId)→ full transaction row readdocument.findFirst / findMany→ second round-tripgetVersionswas worst: 3 sequential queries (tx check → doc existence →documentVersion.findManywithuploadedBy).Fix
Replaced all sequential read chains with Prisma
$transaction([...])batches so the transaction access-select and the document query run in the same database connection checkout.attachlistfindOneaddVersiongetVersionsremoveAdditional improvements:
transaction.findUniquenow usesselect: { id, buyerId, sellerId }— fetches only the access-control fields, not the full row.@ts-nocheckfrom bothtransaction-documents.service.tsanddto/transaction-document.dto.ts.as anycasts with correct Prisma-typed field assignments.TxAccess,DocumentWithVersions,VersionWithUploader,DocumentTypeValue.ensureTransactionExistsmethod.Testing
npm run buildpasses with zero TypeScript errors under strict mode.