Skip to content

perf(#765): drop 6 DB roundtrips in handleTransactionUpdate#862

Open
Xuccessor wants to merge 1 commit into
MettaChain:mainfrom
Xuccessor:fix/issue-765-notifications-preferences-n-plus-1
Open

perf(#765): drop 6 DB roundtrips in handleTransactionUpdate#862
Xuccessor wants to merge 1 commit into
MettaChain:mainfrom
Xuccessor:fix/issue-765-notifications-preferences-n-plus-1

Conversation

@Xuccessor

@Xuccessor Xuccessor commented Jun 30, 2026

Copy link
Copy Markdown

Closes #765
Closes #763
Closes #764
Closes #766

What

Real N+1 in handleTransactionUpdate: the parties query already included user.preferences, but the loop made 6 redundant findUnique roundtrips (3 channels x 2 parties) via userPreferencesService.shouldDeliverNotification(user.id, ...).

Fix

  1. Extract the channel/quiet-hours decision into a pure helper shouldDeliverNotificationFromPrefs(prefs, eventType, channel); the async method becomes a thin shim
  2. Consume the already-included user.preferences in the notifications loop and call the helper 3 times locally per party — zero DB hits

Behavior parity

For users with saved prefs: identical decisions (same 4 checks). For users WITHOUT prefs: prior code triggered an upsert via findByUserId; this PR uses local schema defaults instead — the upsert side-effect is removed on this path only.

Validation

  • tsc: clean
  • npm test: passes (no regression)

@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@Xuccessor 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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment