From 5bb02db85994ea0c017894fb49950c67a6db552e Mon Sep 17 00:00:00 2001 From: CraftyOldMiner <85420839+CraftyOldMiner@users.noreply.github.com> Date: Sun, 27 Mar 2022 12:16:54 -0500 Subject: 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 --- .../moulberry/notenoughupdates/auction/APIManager.java | 14 +++++++++----- .../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 playerBids = new HashSet<>(); private final HashSet playerBidsNotified = new HashSet<>(); private final HashSet 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 mapData = new TreeMap<>(); if (bazaar && item.getValue().getAsJsonObject().has("curr_buy") && item.getValue().getAsJsonObject().has( -- cgit