mirror of
https://github.com/bisq-network/bisq.git
synced 2025-03-13 11:09:10 +01:00
Sum merit in outer loop to speed up VoteResultView.getVotingHistoryJson
Avoid needlessly repetitive (once per cycle proposal) signature checking of each 'Merit' object in the DAO state, when exporting the voting history JSON, by moving the merit calculations to the outer loop over each cycle, storing the sums in a map by blind vote txId. As signature verification is expensive, taking seconds to run just once over every 'Merit' object, this is by far the biggest bottleneck when generating the JSON.
This commit is contained in:
parent
34ed5e0f74
commit
57662ae206
1 changed files with 7 additions and 4 deletions
|
@ -882,6 +882,12 @@ public class VoteResultView extends ActivatableView<GridPane, Void> implements D
|
|||
cycleJson.addProperty("totalAcceptedVotes", cycleListItem.getResultsOfCycle().getNumAcceptedVotes());
|
||||
cycleJson.addProperty("totalRejectedVotes", cycleListItem.getResultsOfCycle().getNumRejectedVotes());
|
||||
|
||||
List<DecryptedBallotsWithMerits> decryptedVotesForCycle = cycleListItem.getResultsOfCycle().getDecryptedVotesForCycle();
|
||||
// Make sure the votes are sorted so we can easier compare json files from different users
|
||||
decryptedVotesForCycle.sort(Comparator.comparing(DecryptedBallotsWithMerits::getBlindVoteTxId));
|
||||
Map<String, Long> meritStakeMap = decryptedVotesForCycle.stream()
|
||||
.collect(Collectors.toMap(DecryptedBallotsWithMerits::getBlindVoteTxId, d -> d.getMerit(daoStateService)));
|
||||
|
||||
JsonArray proposalsArray = new JsonArray();
|
||||
List<EvaluatedProposal> evaluatedProposals = cycleListItem.getResultsOfCycle().getEvaluatedProposals();
|
||||
evaluatedProposals.sort(Comparator.comparingLong(o -> o.getProposal().getCreationDate()));
|
||||
|
@ -973,9 +979,6 @@ public class VoteResultView extends ActivatableView<GridPane, Void> implements D
|
|||
evaluatedProposals.stream()
|
||||
.filter(evaluatedProposal -> evaluatedProposal.getProposal().equals(proposal))
|
||||
.forEach(evaluatedProposal -> {
|
||||
List<DecryptedBallotsWithMerits> decryptedVotesForCycle = cycleListItem.getResultsOfCycle().getDecryptedVotesForCycle();
|
||||
// Make sure the votes are sorted so we can easier compare json files from different users
|
||||
decryptedVotesForCycle.sort(Comparator.comparing(DecryptedBallotsWithMerits::getBlindVoteTxId));
|
||||
decryptedVotesForCycle.forEach(decryptedBallotsWithMerits -> {
|
||||
JsonObject voteJson = new JsonObject();
|
||||
// Domain data of decryptedBallotsWithMerits
|
||||
|
@ -984,7 +987,7 @@ public class VoteResultView extends ActivatableView<GridPane, Void> implements D
|
|||
voteJson.addProperty("voteRevealTxId", decryptedBallotsWithMerits.getVoteRevealTxId());
|
||||
voteJson.addProperty("stake", decryptedBallotsWithMerits.getStake());
|
||||
|
||||
voteJson.addProperty("voteWeight", decryptedBallotsWithMerits.getMerit(daoStateService));
|
||||
voteJson.addProperty("voteWeight", meritStakeMap.get(decryptedBallotsWithMerits.getBlindVoteTxId()));
|
||||
String voteResult = decryptedBallotsWithMerits.getVote(evaluatedProp.getProposalTxId())
|
||||
.map(vote -> vote.isAccepted() ? "Accepted" : "Rejected")
|
||||
.orElse("Ignored");
|
||||
|
|
Loading…
Add table
Reference in a new issue