perf(daemon): drop redundant DISTINCT in getAddressWalletInfo#401
perf(daemon): drop redundant DISTINCT in getAddressWalletInfo#401andreabadesso wants to merge 1 commit intomasterfrom
Conversation
Tier 2 fix #7 from #395. `address.address` is a unique key, so the DISTINCT clause is redundant for this SELECT — it only forces MySQL to add a sort/dedup step on top of the join result. Small per-event savings (~0.5-2ms depending on address count), and the query runs once per event in the sync hot path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/daemon/src/db/index.ts (1)
941-973: Optional: consider aligningwallet-servicefor consistency.The equivalent
getAddressWalletInfoinpackages/wallet-service/src/db/index.ts(lines 227–252) still usesSELECT DISTINCTwith the same join shape. If the reasoning here holds (and it does, given identical schema), the same cleanup could be applied there for consistency — or, conversely, a short note in the commit/PR body explaining why only the daemon path was changed would help future readers. Not blocking for this PR.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/daemon/src/db/index.ts` around lines 941 - 973, The daemon's getAddressWalletInfo removes the redundant SELECT DISTINCT; mirror this change in the wallet-service implementation by updating the getAddressWalletInfo function in packages/wallet-service/src/db/index.ts to remove DISTINCT from the same JOIN query (or add a brief commit/PR note explaining why only the daemon was changed), ensuring the SQL, variable names (e.g., addressWalletMap, AddressesWalletsRow) and result mapping remain consistent with the daemon version.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/daemon/src/db/index.ts`:
- Around line 941-973: The daemon's getAddressWalletInfo removes the redundant
SELECT DISTINCT; mirror this change in the wallet-service implementation by
updating the getAddressWalletInfo function in
packages/wallet-service/src/db/index.ts to remove DISTINCT from the same JOIN
query (or add a brief commit/PR note explaining why only the daemon was
changed), ensuring the SQL, variable names (e.g., addressWalletMap,
AddressesWalletsRow) and result mapping remain consistent with the daemon
version.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: fd486825-94c0-436e-84f6-fe0ebf7489e4
📒 Files selected for processing (1)
packages/daemon/src/db/index.ts
Motivation
Tier 2 fix #7 from #395.
address.addressis a unique key in theaddresstable, so theDISTINCTclause onSELECT DISTINCT a.address, a.wallet_id, ...is logically redundant — the join can't produce duplicate rows. MySQL honors it anyway by adding a sort/dedup step on top of the join result.Small per-event savings (~0.5–2ms depending on address count), but this query runs in the sync hot path so it compounds at mainnet scale.
Branches directly off
master— independent of the benchmarking stack (#396–#400).Acceptance Criteria
DISTINCTremoved from theSELECTingetAddressWalletInfoValidation
yarn tsc --noEmit— cleanyarn test --testPathPattern='db'— 79/79 passChecklist
master, confirm this code is production-ready and can be included in future releases as soon as it gets merged🤖 Generated with Claude Code
Summary by CodeRabbit