Skip to content

Commit

Permalink
Merge pull request #4954 from chimp1984/various-small-improvements
Browse files Browse the repository at this point in the history
Various small improvements
  • Loading branch information
sqrrm authored Dec 15, 2020
2 parents bc60db3 + 7e14573 commit 9b8073b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ public void persistNow(@Nullable Runnable completeHandler) {
// 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();
Expand Down Expand Up @@ -437,7 +440,10 @@ public void writeToDisk(protobuf.PersistableEnvelope serialized, @Nullable Runna
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,6 +77,8 @@ private Role(String uid,
this.name = name;
this.link = link;
this.bondedRoleType = bondedRoleType;

hash = Hash.getSha256Ripemd160hash(toProtoMessage().toByteArray());
}

@Override
Expand All @@ -100,8 +105,7 @@ public static Role fromProto(protobuf.Role proto) {

@Override
public byte[] getHash() {
byte[] bytes = toProtoMessage().toByteArray();
return Hash.getSha256Ripemd160hash(bytes);
return hash;
}

@Override
Expand Down
17 changes: 14 additions & 3 deletions core/src/main/java/bisq/core/offer/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public enum State {
@Setter
transient private PriceFeedService priceFeedService;

// Used only as cache
@Nullable
@JsonExclude
transient private String currencyCode;


///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -346,8 +351,9 @@ public boolean isMyOffer(KeyRing keyRing) {


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();
}
Expand Down Expand Up @@ -421,9 +427,14 @@ public String getCountryCode() {
}

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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ private enum PaymentMethodMapper {
@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,
Expand Down Expand Up @@ -251,6 +255,8 @@ public TradeStatistics3(String currency,
this.extraDataMap = ExtraDataMapValidator.getValidatedExtraDataMap(extraDataMap);

this.hash = hash == null ? createHash() : hash;

dateObj = new Date(date);
}

public byte[] createHash() {
Expand Down Expand Up @@ -319,7 +325,7 @@ public Capabilities getRequiredCapabilities() {

@Override
public Date getDate() {
return new Date(date);
return dateObj;
}

public long getDateAsLong() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public P2PDataStorage(NetworkNode networkNode,
networkNode.addMessageListener(this);
networkNode.addConnectionListener(this);

this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE);
this.persistenceManager.initialize(sequenceNumberMap, PersistenceManager.Source.PRIVATE_LOW_PRIO);
}


Expand Down

0 comments on commit 9b8073b

Please sign in to comment.