cache incoming txs to improve performance of funds tab

This commit is contained in:
woodser 2022-12-23 12:20:19 +00:00
parent a21628ad0d
commit 1c6d4cec83
3 changed files with 18 additions and 9 deletions

View file

@ -59,7 +59,7 @@ class DepositListItem {
return lazyFieldsSupplier.get();
}
DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter) {
DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter, List<MoneroTxWallet> cachedTxs) {
this.xmrWalletService = xmrWalletService;
this.addressEntry = addressEntry;
@ -68,7 +68,7 @@ class DepositListItem {
public void onBalanceChanged(BigInteger balance) {
DepositListItem.this.balanceAsCoin = HavenoUtils.atomicUnitsToCoin(balance);
DepositListItem.this.balance.set(formatter.formatCoin(balanceAsCoin));
updateUsage(addressEntry.getSubaddressIndex());
updateUsage(addressEntry.getSubaddressIndex(), null);
}
};
xmrWalletService.addBalanceListener(balanceListener);
@ -76,7 +76,7 @@ class DepositListItem {
balanceAsCoin = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
balance.set(formatter.formatCoin(balanceAsCoin));
updateUsage(addressEntry.getSubaddressIndex());
updateUsage(addressEntry.getSubaddressIndex(), cachedTxs);
// confidence
lazyFieldsSupplier = Suppliers.memoize(() -> new LazyFields() {{
@ -95,8 +95,8 @@ class DepositListItem {
}});
}
private void updateUsage(int subaddressIndex) {
numTxOutputs = xmrWalletService.getNumTxOutputsForSubaddress(addressEntry.getSubaddressIndex());
private void updateUsage(int subaddressIndex, List<MoneroTxWallet> cachedTxs) {
numTxOutputs = xmrWalletService.getNumTxOutputsForSubaddress(addressEntry.getSubaddressIndex(), cachedTxs);
usage = numTxOutputs == 0 ? Res.get("funds.deposit.unused") : Res.get("funds.deposit.usedInTx", numTxOutputs);
}

View file

@ -52,6 +52,7 @@ import net.glxn.qrgen.image.ImageType;
import javax.inject.Inject;
import javax.inject.Named;
import monero.wallet.model.MoneroTxConfig;
import monero.wallet.model.MoneroTxWallet;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
@ -83,6 +84,7 @@ import javafx.util.Callback;
import java.io.ByteArrayInputStream;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.jetbrains.annotations.NotNull;
@ -298,8 +300,10 @@ public class DepositView extends ActivatableView<VBox, Void> {
private void updateList() {
observableList.forEach(DepositListItem::cleanup);
observableList.clear();
List<MoneroTxWallet> incomingTxs = xmrWalletService.getIncomingTxs(); // cache incoming txs for performance
xmrWalletService.getAvailableAddressEntries()
.forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter)));
.forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter, incomingTxs)));
}
private Coin getAmountAsCoin() {