Dont call local storage if we read from persisted object

This commit is contained in:
Manfred Karrer 2016-10-12 23:18:53 +02:00
parent 2d24fb7ed1
commit 849ab100c3
2 changed files with 8 additions and 6 deletions

View file

@ -239,7 +239,7 @@ public class TradeManager {
trade.getDate(),
(trade.getDepositTx() != null ? trade.getDepositTx().getHashAsString() : ""),
keyRing.getPubKeyRing());
tradeStatisticsManager.add(tradeStatistics);
tradeStatisticsManager.add(tradeStatistics, true);
// We only republish trades from last 10 days
// TODO check if needed at all. Don't want to remove it atm to not risk anything.

View file

@ -69,14 +69,14 @@ public class TradeStatisticsManager {
HashSet<TradeStatistics> persisted = statisticsStorage.initAndGetPersistedWithFileName("TradeStatistics");
if (persisted != null)
persisted.stream().forEach(this::add);
persisted.stream().forEach(e -> add(e, false));
p2PService.addHashSetChangedListener(new HashMapChangedListener() {
@Override
public void onAdded(ProtectedStorageEntry data) {
final StoragePayload storagePayload = data.getStoragePayload();
if (storagePayload instanceof TradeStatistics)
add((TradeStatistics) storagePayload);
add((TradeStatistics) storagePayload, true);
}
@Override
@ -89,17 +89,19 @@ public class TradeStatisticsManager {
p2PService.getP2PDataStorage().getMap().values().forEach(e -> {
final StoragePayload storagePayload = e.getStoragePayload();
if (storagePayload instanceof TradeStatistics)
add((TradeStatistics) storagePayload);
add((TradeStatistics) storagePayload, false);
});
}
public void add(TradeStatistics tradeStatistics) {
public void add(TradeStatistics tradeStatistics, boolean storeLocally) {
if (!tradeStatisticsSet.contains(tradeStatistics)) {
boolean itemAlreadyAdded = tradeStatisticsSet.stream().filter(e -> (e.getOfferId().equals(tradeStatistics.getOfferId()))).findAny().isPresent();
if (!itemAlreadyAdded) {
tradeStatisticsSet.add(tradeStatistics);
observableTradeStatisticsSet.add(tradeStatistics);
statisticsStorage.queueUpForSave(new HashSet<>(tradeStatisticsSet), 2000);
if (storeLocally)
statisticsStorage.queueUpForSave(new HashSet<>(tradeStatisticsSet), 2000);
dump();
} else {