mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Merge pull request #7221 from stejbac/optimise-restapi-stream-filtering
Optimise/simplify some stream filtering for the REST API
This commit is contained in:
commit
5d8641031a
@ -23,7 +23,6 @@ import bisq.core.dao.burningman.model.BurningManCandidate;
|
|||||||
import bisq.common.util.DateUtil;
|
import bisq.common.util.DateUtil;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -54,8 +53,7 @@ public class BalanceModel {
|
|||||||
receivedBtcBalanceEntries.add(balanceEntry);
|
receivedBtcBalanceEntries.add(balanceEntry);
|
||||||
|
|
||||||
Date month = balanceEntry.getMonth();
|
Date month = balanceEntry.getMonth();
|
||||||
receivedBtcBalanceEntriesByMonth.putIfAbsent(month, new HashSet<>());
|
receivedBtcBalanceEntriesByMonth.computeIfAbsent(month, m -> new HashSet<>()).add(balanceEntry);
|
||||||
receivedBtcBalanceEntriesByMonth.get(month).add(balanceEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ReceivedBtcBalanceEntry> getReceivedBtcBalanceEntries() {
|
public Set<ReceivedBtcBalanceEntry> getReceivedBtcBalanceEntries() {
|
||||||
@ -63,11 +61,7 @@ public class BalanceModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Set<ReceivedBtcBalanceEntry> getReceivedBtcBalanceEntriesByMonth(Date month) {
|
public Set<ReceivedBtcBalanceEntry> getReceivedBtcBalanceEntriesByMonth(Date month) {
|
||||||
return receivedBtcBalanceEntriesByMonth.entrySet().stream()
|
return receivedBtcBalanceEntriesByMonth.getOrDefault(month, Set.of());
|
||||||
.filter(e -> e.getKey().equals(month))
|
|
||||||
.map(Map.Entry::getValue)
|
|
||||||
.flatMap(Collection::stream)
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Stream<BurnedBsqBalanceEntry> getBurnedBsqBalanceEntries(Set<BurnOutputModel> burnOutputModels) {
|
public Stream<BurnedBsqBalanceEntry> getBurnedBsqBalanceEntries(Set<BurnOutputModel> burnOutputModels) {
|
||||||
|
@ -33,12 +33,15 @@ import bisq.network.p2p.storage.persistence.AppendOnlyDataStoreService;
|
|||||||
|
|
||||||
import bisq.common.config.Config;
|
import bisq.common.config.Config;
|
||||||
import bisq.common.file.JsonFileManager;
|
import bisq.common.file.JsonFileManager;
|
||||||
|
import bisq.common.util.RangeUtils;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import com.google.common.collect.Range;
|
||||||
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableSet;
|
import javafx.collections.ObservableSet;
|
||||||
|
|
||||||
@ -136,10 +139,10 @@ public class TradeStatisticsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<TradeStatistics3> getTradeStatisticsList(long dateStart, long dateEnd) {
|
public List<TradeStatistics3> getTradeStatisticsList(long dateStart, long dateEnd) {
|
||||||
return observableTradeStatisticsSet.stream()
|
return new ArrayList<>(RangeUtils.subSet(navigableTradeStatisticsSet)
|
||||||
.filter(x -> x.getDateAsLong() > dateStart && x.getDateAsLong() <= dateEnd)
|
.withKey(TradeStatistics3::getDateAsLong)
|
||||||
.sorted((o1, o2) -> (Long.compare(o2.getDateAsLong(), o1.getDateAsLong())))
|
.overRange(Range.openClosed(Math.min(dateStart, dateEnd), dateEnd))
|
||||||
.collect(Collectors.toList());
|
.descendingSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeDumpStatistics() {
|
private void maybeDumpStatistics() {
|
||||||
|
@ -103,8 +103,8 @@ public final class CallRateMeteringInterceptor implements ServerInterceptor {
|
|||||||
|
|
||||||
private Optional<Map.Entry<String, GrpcCallRateMeter>> getRateMeterKV(ServerCall<?, ?> serverCall) {
|
private Optional<Map.Entry<String, GrpcCallRateMeter>> getRateMeterKV(ServerCall<?, ?> serverCall) {
|
||||||
String rateMeterKey = getRateMeterKey(serverCall);
|
String rateMeterKey = getRateMeterKey(serverCall);
|
||||||
return serviceCallRateMeters.entrySet().stream()
|
return Optional.ofNullable(serviceCallRateMeters.get(rateMeterKey))
|
||||||
.filter((e) -> e.getKey().equals(rateMeterKey)).findFirst();
|
.map(meter -> Map.entry(rateMeterKey, meter));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRateMeterKey(ServerCall<?, ?> serverCall) {
|
private String getRateMeterKey(ServerCall<?, ?> serverCall) {
|
||||||
|
@ -22,11 +22,10 @@ import bisq.core.dao.state.model.blockchain.BaseTx;
|
|||||||
import bisq.core.dao.state.model.blockchain.Tx;
|
import bisq.core.dao.state.model.blockchain.Tx;
|
||||||
import bisq.core.dao.state.model.blockchain.TxType;
|
import bisq.core.dao.state.model.blockchain.TxType;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -86,10 +85,7 @@ public class ExplorerTransactionsApi {
|
|||||||
address = address.substring(1, address.length());
|
address = address.substring(1, address.length());
|
||||||
}
|
}
|
||||||
String finalAddress = address;
|
String finalAddress = address;
|
||||||
List<JsonTx> result = daoStateService.getTxIdSetByAddress().entrySet().stream()
|
List<JsonTx> result = daoStateService.getTxIdSetByAddress().getOrDefault(finalAddress, Set.of()).stream()
|
||||||
.filter(e -> e.getKey().equals(finalAddress))
|
|
||||||
.map(Map.Entry::getValue)
|
|
||||||
.flatMap(Collection::stream)
|
|
||||||
.flatMap(txId -> daoStateService.getTx(txId).stream())
|
.flatMap(txId -> daoStateService.getTx(txId).stream())
|
||||||
.map(tx -> BlockDataToJsonConverter.getJsonTx(daoStateService, tx))
|
.map(tx -> BlockDataToJsonConverter.getJsonTx(daoStateService, tx))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
Loading…
Reference in New Issue
Block a user