Merge pull request #4954 from chimp1984/various-small-improvements

Various small improvements
This commit is contained in:
sqrrm 2020-12-15 23:04:15 +01:00 committed by GitHub
commit 9b8073b94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 9 deletions

View File

@ -375,7 +375,10 @@ public class PersistenceManager<T extends PersistableEnvelope> {
// reference to the persistable object.
getWriteToDiskExecutor().execute(() -> writeToDisk(serialized, completeHandler));
log.info("Serializing {} took {} msec", fileName, System.currentTimeMillis() - ts);
long duration = System.currentTimeMillis() - ts;
if (duration > 100) {
log.info("Serializing {} took {} msec", fileName, duration);
}
} catch (Throwable e) {
log.error("Error in saveToFile toProtoMessage: {}, {}", persistable.getClass().getSimpleName(), fileName);
e.printStackTrace();
@ -437,7 +440,10 @@ public class PersistenceManager<T extends PersistableEnvelope> {
e.printStackTrace();
log.error("Cannot close resources." + e.getMessage());
}
log.info("Writing the serialized {} completed in {} msec", fileName, System.currentTimeMillis() - ts);
long duration = System.currentTimeMillis() - ts;
if (duration > 100) {
log.info("Writing the serialized {} completed in {} msec", fileName, duration);
}
persistenceRequested = false;
if (completeHandler != null) {
UserThread.execute(completeHandler);

View File

@ -46,6 +46,9 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss
private final String link;
private final BondedRoleType bondedRoleType;
// Only used as cache
transient private final byte[] hash;
/**
* @param name Full name or nickname
* @param link GitHub account or forum account of user
@ -74,6 +77,8 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss
this.name = name;
this.link = link;
this.bondedRoleType = bondedRoleType;
hash = Hash.getSha256Ripemd160hash(toProtoMessage().toByteArray());
}
@Override
@ -100,8 +105,7 @@ public final class Role implements PersistablePayload, NetworkPayload, BondedAss
@Override
public byte[] getHash() {
byte[] bytes = toProtoMessage().toByteArray();
return Hash.getSha256Ripemd160hash(bytes);
return hash;
}
@Override

View File

@ -109,6 +109,11 @@ public class Offer implements NetworkPayload, PersistablePayload {
@Setter
transient private PriceFeedService priceFeedService;
// Used only as cache
@Nullable
@JsonExclude
transient private String currencyCode;
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -346,8 +351,9 @@ public class Offer implements NetworkPayload, PersistablePayload {
public Optional<String> getAccountAgeWitnessHashAsHex() {
if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH))
return Optional.of(getExtraDataMap().get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH));
Map<String, String> extraDataMap = getExtraDataMap();
if (extraDataMap != null && extraDataMap.containsKey(OfferPayload.ACCOUNT_AGE_WITNESS_HASH))
return Optional.of(extraDataMap.get(OfferPayload.ACCOUNT_AGE_WITNESS_HASH));
else
return Optional.empty();
}
@ -421,9 +427,14 @@ public class Offer implements NetworkPayload, PersistablePayload {
}
public String getCurrencyCode() {
return offerPayload.getBaseCurrencyCode().equals("BTC") ?
if (currencyCode != null) {
return currencyCode;
}
currencyCode = offerPayload.getBaseCurrencyCode().equals("BTC") ?
offerPayload.getCounterCurrencyCode() :
offerPayload.getBaseCurrencyCode();
return currencyCode;
}
public long getProtocolVersion() {

View File

@ -182,6 +182,10 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
@Getter
private final Map<String, String> extraDataMap;
// We cache the date object to avoid reconstructing a new Date at each getDate call.
@JsonExclude
private transient final Date dateObj;
public TradeStatistics3(String currency,
long price,
long amount,
@ -251,6 +255,8 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);
this.hash = hash == null ? createHash() : hash;
dateObj = new Date(date);
}
public byte[] createHash() {
@ -319,7 +325,7 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
@Override
public Date getDate() {
return new Date(date);
return dateObj;
}
public long getDateAsLong() {

View File

@ -177,7 +177,7 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
networkNode.addMessageListener(this);
networkNode.addConnectionListener(this);
this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE);
this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE_LOW_PRIO);
}