Skip to content

Commit

Permalink
Merge pull request #5010 from chimp1984/dao-performance-improvements
Browse files Browse the repository at this point in the history
Dao performance improvements
  • Loading branch information
ripcurlx committed Dec 28, 2020
2 parents 195c2b8 + 7a9230e commit 785c76e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/bisq/core/dao/DaoFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public Coin getGenesisTotalSupply() {
}

public int getNumIssuanceTransactions(IssuanceType issuanceType) {
return daoStateService.getIssuanceSet(issuanceType).size();
return daoStateService.getIssuanceSetForType(issuanceType).size();
}

public Set<Tx> getBurntFeeTxs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public MeritList getMerits(@Nullable String blindVoteTxId) {
.filter(txId -> periodService.isTxInPastCycle(txId, periodService.getChainHeight()))
.collect(Collectors.toSet());

return new MeritList(daoStateService.getIssuanceSet(IssuanceType.COMPENSATION).stream()
return new MeritList(daoStateService.getIssuanceSetForType(IssuanceType.COMPENSATION).stream()
.map(issuance -> {
checkArgument(issuance.getIssuanceType() == IssuanceType.COMPENSATION,
"IssuanceType must be COMPENSATION for MeritList");
Expand Down
11 changes: 3 additions & 8 deletions core/src/main/java/bisq/core/dao/state/DaoStateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -597,23 +597,18 @@ public void addIssuance(Issuance issuance) {
daoState.getIssuanceMap().put(issuance.getTxId(), issuance);
}

public Set<Issuance> getIssuanceSet(IssuanceType issuanceType) {
public Set<Issuance> getIssuanceSetForType(IssuanceType issuanceType) {
return daoState.getIssuanceMap().values().stream()
.filter(issuance -> issuance.getIssuanceType() == issuanceType)
.collect(Collectors.toSet());
}

public Optional<Issuance> getIssuance(String txId, IssuanceType issuanceType) {
return daoState.getIssuanceMap().values().stream()
.filter(issuance -> issuance.getTxId().equals(txId))
.filter(issuance -> issuance.getIssuanceType() == issuanceType)
.findAny();
return getIssuance(txId).filter(issuance -> issuance.getIssuanceType() == issuanceType);
}

public Optional<Issuance> getIssuance(String txId) {
return daoState.getIssuanceMap().values().stream()
.filter(issuance -> issuance.getTxId().equals(txId))
.findAny();
return Optional.ofNullable(daoState.getIssuanceMap().get(txId));
}

public boolean isIssuanceTx(String txId) {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/dao/state/model/DaoState.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public static DaoState getClone(DaoState daoState) {
private final LinkedList<Cycle> cycles;

// These maps represent mutual data which can get changed at parsing a transaction
// We use TreeMaps instead of HashMaps because we need deterministic sorting of the maps for the hashChains
// used for the DAO monitor.
@Getter
private final TreeMap<TxOutputKey, TxOutput> unspentTxOutputMap;
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@

import javafx.util.StringConverter;

import java.text.DecimalFormat;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
Expand All @@ -73,6 +71,8 @@
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

import java.text.DecimalFormat;

import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -630,10 +630,10 @@ private List<Number> updateBSQIssuedMonthly() {
.toLocalDate()
.with(ADJUSTERS.get(MONTH)));

Stream<Issuance> bsqByCompensation = daoStateService.getIssuanceSet(IssuanceType.COMPENSATION).stream()
Stream<Issuance> bsqByCompensation = daoStateService.getIssuanceSetForType(IssuanceType.COMPENSATION).stream()
.sorted(Comparator.comparing(Issuance::getChainHeight));

Stream<Issuance> bsqByReimbursement = daoStateService.getIssuanceSet(IssuanceType.REIMBURSEMENT).stream()
Stream<Issuance> bsqByReimbursement = daoStateService.getIssuanceSetForType(IssuanceType.REIMBURSEMENT).stream()
.sorted(Comparator.comparing(Issuance::getChainHeight));

Map<LocalDate, List<Issuance>> bsqAddedByVote = Stream.concat(bsqByCompensation, bsqByReimbursement)
Expand Down

0 comments on commit 785c76e

Please sign in to comment.