diff options
author | CraftyOldMiner <85420839+CraftyOldMiner@users.noreply.github.com> | 2022-03-27 12:16:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-27 19:16:54 +0200 |
commit | 5bb02db85994ea0c017894fb49950c67a6db552e (patch) | |
tree | 51a0d1c5fa3c60baa8609086187bf3cd49b1d193 /src/main/java/io | |
parent | 9d763c980646510b483d2460b45cf1ff2f3ba4db (diff) | |
download | NotEnoughUpdates-5bb02db85994ea0c017894fb49950c67a6db552e.tar.gz NotEnoughUpdates-5bb02db85994ea0c017894fb49950c67a6db552e.tar.bz2 NotEnoughUpdates-5bb02db85994ea0c017894fb49950c67a6db552e.zip |
Lowest BIN related fixes & optimizations (#101)
* Lowest BIN related fixes & optimizations
- Fix double-call of updateLowestBin due to a race condition where lastLowestBinUpdate is not updated by the async thread until after the following tick.
- Change the parsing of item prices to avoid using getAsInt on a decimal string that throws two exceptions per value parsed. I replaced it with the code that getAsInt ends up falling back to.
- Delete corrupted prices_*.gz file so that it can be re-downloaded.
- Make the Bazaar update retry after 60 seconds instead of 5 minutes to be consistent with auction average data.
* Remove corrupt file deletion code to avoid conflict with other PR
Diffstat (limited to 'src/main/java/io')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java | 14 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java | 2 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java index c47e0844..f46c8334 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/auction/APIManager.java @@ -41,6 +41,9 @@ public class APIManager { private final HashSet<String> playerBids = new HashSet<>(); private final HashSet<String> playerBidsNotified = new HashSet<>(); private final HashSet<String> playerBidsFinishedNotified = new HashSet<>(); + private final int LOWEST_BIN_UPDATE_INTERVAL = 2 * 60 * 1000; // 2 minutes + private final int AUCTION_AVG_UPDATE_INTERVAL = 5 * 60 * 1000; // 5 minutes + private final int BAZAAR_UPDATE_INTERVAL = 5 * 60 * 1000; // 5 minutes private JsonObject lowestBins = null; private JsonObject auctionPricesAvgLowestBinJson = null; @@ -203,15 +206,16 @@ public class APIManager { } } } - if (currentTime - lastAuctionAvgUpdate > 5 * 60 * 1000) { //5 minutes - lastAuctionAvgUpdate = currentTime - 4 * 60 * 1000; //Try again in 1 minute if updateAvgPrices doesn't succeed + if (currentTime - lastAuctionAvgUpdate > AUCTION_AVG_UPDATE_INTERVAL) { + lastAuctionAvgUpdate = currentTime - AUCTION_AVG_UPDATE_INTERVAL + 60 * 1000; // Try again in 1 minute on failure updateAvgPrices(); } - if (currentTime - lastBazaarUpdate > 5 * 60 * 1000) { //5 minutes - lastBazaarUpdate = currentTime; + if (currentTime - lastBazaarUpdate > BAZAAR_UPDATE_INTERVAL) { + lastBazaarUpdate = currentTime - BAZAAR_UPDATE_INTERVAL + 60 * 1000; // Try again in 1 minute on failure updateBazaar(); } - if (currentTime - lastLowestBinUpdate > 2 * 60 * 1000) { + if (currentTime - lastLowestBinUpdate > LOWEST_BIN_UPDATE_INTERVAL) { + lastLowestBinUpdate = currentTime - LOWEST_BIN_UPDATE_INTERVAL + 30 * 1000; // Try again in 30 seconds on failure updateLowestBin(); } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java index 63a08d41..66014b1f 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/GuiPriceGraph.java @@ -418,7 +418,7 @@ public class GuiPriceGraph extends GuiScreen { item.getValue().getAsJsonObject().get("curr_sell").getAsFloat() )); else if (!bazaar) - prices.get(item.getKey()).ah.put(epochSecond, item.getValue().getAsInt()); + prices.get(item.getKey()).ah.put(epochSecond, item.getValue().getAsBigDecimal().intValue()); } else { TreeMap<Long, Object> mapData = new TreeMap<>(); if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has( |