Skip to content

Fix/web3 transactions query performance#6457

Open
SeniorZhai wants to merge 4 commits into
masterfrom
fix/web3-transactions-query-performance
Open

Fix/web3 transactions query performance#6457
SeniorZhai wants to merge 4 commits into
masterfrom
fix/web3-transactions-query-performance

Conversation

@SeniorZhai

Copy link
Copy Markdown
Member

No description provided.

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.
@SeniorZhai SeniorZhai requested a review from Copilot June 16, 2026 09:06
@SeniorZhai SeniorZhai added the testing Now testing, but you can review label Jun 16, 2026

Copilot AI 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.

⚠️ 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 DISTINCT and scoping token joins by wallet_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.

Comment on lines 371 to 376
val fiatRate = Fiats.getRate().toBigDecimal()
val tokenFiat = calculateWalletHomeTokenFiat(
totalUsd = BigDecimal.valueOf(tokenSummary.totalUsd),
fiatRate = fiatRate,
)
val totalFiat = calculateWalletHomeTotalFiat(tokenFiat, positions.positionMarginUsdTotal())
Comment on lines +476 to +486
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,
)
Comment on lines 7 to +15
internal fun calculateWalletHomeTotalFiat(
tokenFiat: BigDecimal,
positionUsd: BigDecimal,
): BigDecimal = tokenFiat + positionUsd

internal fun calculateWalletHomeTokenFiat(
totalUsd: BigDecimal,
fiatRate: BigDecimal,
): BigDecimal = totalUsd.multiply(fiatRate)
@SeniorZhai SeniorZhai removed the testing Now testing, but you can review label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants