mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
Change handling of delay at republishing
The delay was too long. Some users have 100 - 200 offers and with the 700 ms delay it takes 70-140 sec. This causes more stress for the network and UI due permanent adding of offers. We decreased delay to 30 ms per offer. So with 200 offers it would be about 6 sec. Maybe we could reduce it even further but as it is hard to test in the live network with so many offers it is better to not be too radical with the change.
This commit is contained in:
parent
b55313054a
commit
7bfbd0fd79
1 changed files with 33 additions and 22 deletions
|
@ -871,32 +871,36 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void republishOffers() {
|
||||
int size = openOffers.size();
|
||||
final ArrayList<OpenOffer> openOffersList = new ArrayList<>(openOffers.getList());
|
||||
if (!stopped) {
|
||||
stopPeriodicRefreshOffersTimer();
|
||||
for (int i = 0; i < size; i++) {
|
||||
// we delay to avoid reaching throttle limits
|
||||
|
||||
long delay = 700;
|
||||
final long minDelay = (i + 1) * delay;
|
||||
final long maxDelay = (i + 2) * delay;
|
||||
final OpenOffer openOffer = openOffersList.get(i);
|
||||
UserThread.runAfterRandomDelay(() -> {
|
||||
if (openOffers.contains(openOffer)) {
|
||||
String id = openOffer.getId();
|
||||
if (id != null && !openOffer.isDeactivated())
|
||||
republishOffer(openOffer);
|
||||
}
|
||||
|
||||
}, minDelay, maxDelay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
} else {
|
||||
log.debug("We have stopped already. We ignore that republishOffers call.");
|
||||
if (stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<OpenOffer> openOffersList = new ArrayList<>(openOffers.getList());
|
||||
republishOffers(openOffersList);
|
||||
|
||||
stopPeriodicRefreshOffersTimer();
|
||||
}
|
||||
|
||||
private void republishOffers(List<OpenOffer> list) {
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
OpenOffer openOffer = list.remove(0);
|
||||
if (!openOffers.contains(openOffer) || openOffer.isDeactivated()) {
|
||||
republishOffers(list);
|
||||
}
|
||||
|
||||
republishOffer(openOffer,
|
||||
() -> UserThread.runAfter(() -> republishOffers(list),
|
||||
30, TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
private void republishOffer(OpenOffer openOffer) {
|
||||
republishOffer(openOffer, null);
|
||||
}
|
||||
|
||||
private void republishOffer(OpenOffer openOffer, @Nullable Runnable completeHandler) {
|
||||
offerBookService.addOffer(openOffer.getOffer(),
|
||||
() -> {
|
||||
if (!stopped) {
|
||||
|
@ -904,6 +908,9 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
if (periodicRefreshOffersTimer == null) {
|
||||
startPeriodicRefreshOffersTimer();
|
||||
}
|
||||
if (completeHandler != null) {
|
||||
completeHandler.run();
|
||||
}
|
||||
}
|
||||
},
|
||||
errorMessage -> {
|
||||
|
@ -912,6 +919,10 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
|
|||
stopRetryRepublishOffersTimer();
|
||||
retryRepublishOffersTimer = UserThread.runAfter(OpenOfferManager.this::republishOffers,
|
||||
RETRY_REPUBLISH_DELAY_SEC);
|
||||
|
||||
if (completeHandler != null) {
|
||||
completeHandler.run();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue