mirror of
https://github.com/boldsuck/haveno.git
synced 2025-01-03 14:49:25 +00:00
cache incoming txs to improve performance of funds tab
This commit is contained in:
parent
a21628ad0d
commit
1c6d4cec83
3 changed files with 18 additions and 9 deletions
|
@ -914,16 +914,21 @@ public class XmrWalletService {
|
||||||
return getNumTxOutputsForSubaddress(subaddressIndex, null);
|
return getNumTxOutputsForSubaddress(subaddressIndex, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getNumTxOutputsForSubaddress(int subaddressIndex, List<MoneroTxWallet> incomingTxs) {
|
public int getNumTxOutputsForSubaddress(int subaddressIndex, List<MoneroTxWallet> incomingTxs) {
|
||||||
if (incomingTxs == null) incomingTxs = getIncomingTxs(subaddressIndex);
|
if (incomingTxs == null) incomingTxs = getIncomingTxs(subaddressIndex);
|
||||||
int numUnspentOutputs = 0;
|
int numUnspentOutputs = 0;
|
||||||
for (MoneroTxWallet tx : incomingTxs) {
|
for (MoneroTxWallet tx : incomingTxs) {
|
||||||
|
if (tx.getTransfers(new MoneroTransferQuery().setSubaddressIndex(subaddressIndex)).isEmpty()) continue;
|
||||||
numUnspentOutputs += tx.isConfirmed() ? tx.getOutputsWallet(new MoneroOutputQuery().setSubaddressIndex(subaddressIndex)).size() : 1; // TODO: monero-project does not provide outputs for unconfirmed txs
|
numUnspentOutputs += tx.isConfirmed() ? tx.getOutputsWallet(new MoneroOutputQuery().setSubaddressIndex(subaddressIndex)).size() : 1; // TODO: monero-project does not provide outputs for unconfirmed txs
|
||||||
}
|
}
|
||||||
return numUnspentOutputs;
|
return numUnspentOutputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<MoneroTxWallet> getIncomingTxs(Integer subaddressIndex) {
|
public List<MoneroTxWallet> getIncomingTxs() {
|
||||||
|
return getIncomingTxs(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MoneroTxWallet> getIncomingTxs(Integer subaddressIndex) {
|
||||||
return wallet.getTxs(new MoneroTxQuery()
|
return wallet.getTxs(new MoneroTxQuery()
|
||||||
.setTransferQuery((new MoneroTransferQuery()
|
.setTransferQuery((new MoneroTransferQuery()
|
||||||
.setAccountIndex(0)
|
.setAccountIndex(0)
|
||||||
|
@ -970,7 +975,7 @@ public class XmrWalletService {
|
||||||
|
|
||||||
// TODO (woodser): update balance and other listening
|
// TODO (woodser): update balance and other listening
|
||||||
public void addBalanceListener(XmrBalanceListener listener) {
|
public void addBalanceListener(XmrBalanceListener listener) {
|
||||||
balanceListeners.add(listener);
|
if (!balanceListeners.contains(listener)) balanceListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeBalanceListener(XmrBalanceListener listener) {
|
public void removeBalanceListener(XmrBalanceListener listener) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ class DepositListItem {
|
||||||
return lazyFieldsSupplier.get();
|
return lazyFieldsSupplier.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter) {
|
DepositListItem(XmrAddressEntry addressEntry, XmrWalletService xmrWalletService, CoinFormatter formatter, List<MoneroTxWallet> cachedTxs) {
|
||||||
this.xmrWalletService = xmrWalletService;
|
this.xmrWalletService = xmrWalletService;
|
||||||
this.addressEntry = addressEntry;
|
this.addressEntry = addressEntry;
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ class DepositListItem {
|
||||||
public void onBalanceChanged(BigInteger balance) {
|
public void onBalanceChanged(BigInteger balance) {
|
||||||
DepositListItem.this.balanceAsCoin = HavenoUtils.atomicUnitsToCoin(balance);
|
DepositListItem.this.balanceAsCoin = HavenoUtils.atomicUnitsToCoin(balance);
|
||||||
DepositListItem.this.balance.set(formatter.formatCoin(balanceAsCoin));
|
DepositListItem.this.balance.set(formatter.formatCoin(balanceAsCoin));
|
||||||
updateUsage(addressEntry.getSubaddressIndex());
|
updateUsage(addressEntry.getSubaddressIndex(), null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
xmrWalletService.addBalanceListener(balanceListener);
|
xmrWalletService.addBalanceListener(balanceListener);
|
||||||
|
@ -76,7 +76,7 @@ class DepositListItem {
|
||||||
balanceAsCoin = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
|
balanceAsCoin = xmrWalletService.getBalanceForSubaddress(addressEntry.getSubaddressIndex());
|
||||||
balance.set(formatter.formatCoin(balanceAsCoin));
|
balance.set(formatter.formatCoin(balanceAsCoin));
|
||||||
|
|
||||||
updateUsage(addressEntry.getSubaddressIndex());
|
updateUsage(addressEntry.getSubaddressIndex(), cachedTxs);
|
||||||
|
|
||||||
// confidence
|
// confidence
|
||||||
lazyFieldsSupplier = Suppliers.memoize(() -> new LazyFields() {{
|
lazyFieldsSupplier = Suppliers.memoize(() -> new LazyFields() {{
|
||||||
|
@ -95,8 +95,8 @@ class DepositListItem {
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUsage(int subaddressIndex) {
|
private void updateUsage(int subaddressIndex, List<MoneroTxWallet> cachedTxs) {
|
||||||
numTxOutputs = xmrWalletService.getNumTxOutputsForSubaddress(addressEntry.getSubaddressIndex());
|
numTxOutputs = xmrWalletService.getNumTxOutputsForSubaddress(addressEntry.getSubaddressIndex(), cachedTxs);
|
||||||
usage = numTxOutputs == 0 ? Res.get("funds.deposit.unused") : Res.get("funds.deposit.usedInTx", numTxOutputs);
|
usage = numTxOutputs == 0 ? Res.get("funds.deposit.unused") : Res.get("funds.deposit.usedInTx", numTxOutputs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,7 @@ import net.glxn.qrgen.image.ImageType;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import monero.wallet.model.MoneroTxConfig;
|
import monero.wallet.model.MoneroTxConfig;
|
||||||
|
import monero.wallet.model.MoneroTxWallet;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
@ -83,6 +84,7 @@ import javafx.util.Callback;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -298,8 +300,10 @@ public class DepositView extends ActivatableView<VBox, Void> {
|
||||||
private void updateList() {
|
private void updateList() {
|
||||||
observableList.forEach(DepositListItem::cleanup);
|
observableList.forEach(DepositListItem::cleanup);
|
||||||
observableList.clear();
|
observableList.clear();
|
||||||
|
|
||||||
|
List<MoneroTxWallet> incomingTxs = xmrWalletService.getIncomingTxs(); // cache incoming txs for performance
|
||||||
xmrWalletService.getAvailableAddressEntries()
|
xmrWalletService.getAvailableAddressEntries()
|
||||||
.forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter)));
|
.forEach(e -> observableList.add(new DepositListItem(e, xmrWalletService, formatter, incomingTxs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Coin getAmountAsCoin() {
|
private Coin getAmountAsCoin() {
|
||||||
|
|
Loading…
Reference in a new issue