Fix/web3 transactions query performance#6457
Conversation
Filter the three token joins by wallet_id and drop the now-redundant DISTINCT so the all-transactions paging query uses the (address, transaction_at) index with a LIMIT early-out instead of materializing and de-duplicating the entire result set. Also disable paging placeholders to skip the COUNT query that scanned the whole table on wallets with many transactions.
There was a problem hiding this comment.
⚠️ Not ready to approve
The Wallet Home header totals are no longer populated (renderPie removed with no replacement), and the updated balance helpers expose a likely currency-mixing issue (fiat + USD) that can miscompute totals for non-USD users.
Pull request overview
This PR aims to improve Wallet Home and Web3 transaction query performance by reducing query cost (removing unnecessary DISTINCT, adding wallet-scoped joins), limiting token preview queries, and introducing aggregate “summary” queries to avoid loading full token lists just to compute totals.
Changes:
- Optimized Web3 transactions query by removing
DISTINCTand scoping token joins bywallet_id. - Added
WalletHomeTokenSummary+ new DAO/repository/viewmodel methods to fetch wallet-home token previews and aggregated totals/counts. - Tweaked paging behavior (
enablePlaceholders = false) for Web3 transactions paging.
File summaries
| File | Description |
|---|---|
| app/src/test/java/one/mixin/android/ui/wallet/home/WalletHomeBalanceTest.kt | Adds unit tests for the new wallet-home balance helper functions. |
| app/src/main/java/one/mixin/android/vo/WalletHomeTokenSummary.kt | Introduces a Room-mapped aggregate summary model for wallet-home totals/counts. |
| app/src/main/java/one/mixin/android/ui/wallet/Web3FilterParams.kt | Removes DISTINCT and scopes token joins by wallet_id to reduce duplication/work. |
| app/src/main/java/one/mixin/android/ui/wallet/WalletViewModel.kt | Exposes new wallet-home token preview/summary APIs; disables placeholders for Web3 paging. |
| app/src/main/java/one/mixin/android/ui/wallet/WalletHomePrivacyFragment.kt | Switches to preview + summary queries; updates total/BTC calculations to use aggregates. |
| app/src/main/java/one/mixin/android/ui/wallet/WalletHomeClassicFragment.kt | Switches to preview + summary queries for Web3 wallet home; updates total/BTC calculations. |
| app/src/main/java/one/mixin/android/ui/wallet/home/WalletHomeBalance.kt | Adds helper functions for fiat/BTC totals and positions margin aggregation. |
| app/src/main/java/one/mixin/android/ui/home/web3/Web3ViewModel.kt | Exposes repository methods for wallet-home token preview/summary. |
| app/src/main/java/one/mixin/android/repository/Web3Repository.kt | Adds wallet-home token preview/summary repository functions. |
| app/src/main/java/one/mixin/android/repository/TokenRepository.kt | Adds wallet-home token preview/summary repository functions. |
| app/src/main/java/one/mixin/android/db/web3/Web3TokenDao.kt | Adds wallet-home preview query + aggregate summary query for Web3 tokens. |
| app/src/main/java/one/mixin/android/db/TokenDao.kt | Adds wallet-home preview query + aggregate summary query for main tokens. |
Copilot's findings
- Files reviewed: 12/12 changed files
- Comments generated: 3
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| val fiatRate = Fiats.getRate().toBigDecimal() | ||
| val tokenFiat = calculateWalletHomeTokenFiat( | ||
| totalUsd = BigDecimal.valueOf(tokenSummary.totalUsd), | ||
| fiatRate = fiatRate, | ||
| ) | ||
| val totalFiat = calculateWalletHomeTotalFiat(tokenFiat, positions.positionMarginUsdTotal()) |
| val fiatRate = Fiats.getRate().toBigDecimal() | ||
| val totalFiat = calculateWalletHomeTokenFiat( | ||
| totalUsd = BigDecimal.valueOf(tokenSummary.totalUsd), | ||
| fiatRate = fiatRate, | ||
| ) | ||
| val totalBtc = calculateWalletHomeBtcTotal( | ||
| tokenFiat = totalFiat, | ||
| tokenBtc = BigDecimal.valueOf(tokenSummary.totalBtc), | ||
| bitcoinPriceUsd = homeBitcoinPriceUsd(), | ||
| fiatRate = fiatRate, | ||
| ) |
| internal fun calculateWalletHomeTotalFiat( | ||
| tokenFiat: BigDecimal, | ||
| positionUsd: BigDecimal, | ||
| ): BigDecimal = tokenFiat + positionUsd | ||
|
|
||
| internal fun calculateWalletHomeTokenFiat( | ||
| totalUsd: BigDecimal, | ||
| fiatRate: BigDecimal, | ||
| ): BigDecimal = totalUsd.multiply(fiatRate) |
No description provided.