tech-debt batch 4: rename currentCharges + hot-path query dedupe (#153/#154)#167
Merged
Conversation
…ath queries (#154) #153 — rename the in-memory fields literally named `totalDueAmount` that actually carry `currentCharges` (standards §1: currentCharges is canonical, never the API totalDueAmount). Pure rename, value-preserving: - series.ts BillInput.totalDueAmount -> currentCharges (+ its read into billTotal) - queries.ts series feed (line ~159) now produces `currentCharges:` and shapeBill's derived field is `currentCharges`; lifetimeSpend + latestBill readers follow - csv.ts BillCsvRow.totalDueAmount -> currentCharges (emitted under the `currentCharges` CSV header, unchanged) - notifications.ts NotificationsOverview.latestBill / NotificationBill / NotificationBillInput -> currentCharges - wire/in-app readers updated in lockstep (useDashboardData, BillsPanel, statSpec, SettingsView) so displayed values are byte-identical The `?? b.totalDueAmount` fallback (for a bill whose PDF isn't parsed yet) is kept EXACTLY as-is so produced numbers + /api/verify stay identical; whether to keep falling back to the forbidden API field is flagged as a separate decision. The PERSISTED Notification.payload JSON key stays `totalDueAmount` (a new distinct NotificationBillPayload type) — renaming it would not be byte-identical on existing prod rows (skipDuplicates never rewrites them; the bell reads the persisted key). #154 — remove redundant hot-path queries, behavior-preserving: - new getAccountMeta(accountId): the ~5 scalars /api/settings actually uses (account/billCount/firstStatement/latestBill/schedule) via cheap queries, no series/Kalman/projection/anomaly/budget pipeline; /api/settings now calls it - getMonthlySeries accepts optional pre-fetched {account, bills}; getOverview gathers account+bills once and feeds both itself and the series (was running account.findUnique + bill.findMany twice per /api/overview hit). Series is order-independent of the bills, so reuse yields a byte-identical result. Docker test stage: 973 tests pass. Production builder (eslint + tsc + next build): green. /api/verify must still be confirmed green on staging's real account.
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.
Tech-debt batch 4 — numeric-path cleanup (epic #161). Behavior-preserving; produced money values are byte-identical.
Closes #153, closes #154.
#153 — rename misleading
totalDueAmount-named fields →currentChargesThe in-memory derived fields that carry
currentChargeswere namedtotalDueAmount(the field standards §1 forbids for analysis). Renamed acrossseries.ts(BillInput),queries.tsfeed +shapeBill/latestBill,csv.ts(BillCsvRow, same CSV header),notifications.tsshapes, and in-lockstep readers (useDashboardData,BillsPanel,statSpec,SettingsView) + tests. The real PrismaBill.totalDueAmountcolumn and the NG-API field are untouched.?? b.totalDueAmountfallback (for a bill whose PDF isn't parsed yet) is kept exactly (no value change). Whether to keep falling back to the forbidden API field is a separate semantic decision — flagged on Rename totalDueAmount-named fields that actually carry currentCharges #153, not changed here.Notification.payloadJSON key is deliberately kept astotalDueAmount(renaming it wouldn't be byte-identical for existing prod rows —syncNotificationsupserts skipDuplicates andNotificationsBellreads the key). Append-only discipline (standards §6).#154 — hot-path query efficiency (behavior-preserving)
getAccountMeta(accountId)(account + billCount + first/latest statement + schedule) —/api/settingsuses it instead of the fullgetOverview(was running Kalman/projection/anomaly/series for ~5 scalars). Settings JSON unchanged.getMonthlySeriesnow accepts optional prefetched{account, bills};getOverviewfetches them once and feeds both itself and the series (was running the same account+bills queries twice per/api/overview). Series is order-independent of bill order (Map aggregation) → byte-identical.Verification (local)
GET /api/verifygreen on staging's real data before release.