Skip to content

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

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
Xuccessor:fix/issue-765-notifications-preferences-n-plus-1
Jun 30, 2026
Merged

perf(#765): drop 6 DB roundtrips in handleTransactionUpdate#862
nanaf6203-bit merged 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
Contributor

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

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit nanaf6203-bit merged commit db5f505 into MettaChain:main Jun 30, 2026
5 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

2 participants