From 1001ddf11b1af4eb860815b2740e73a65097f312 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 20 Dec 2018 14:04:15 -0500 Subject: [PATCH] xp tracker: limit lookups to most 1 per 3 seconds Drop the rest to prevent backlogging. The hiscore API throttling is fairly strict. --- .../http/service/xp/XpTrackerController.java | 4 ++-- .../http/service/xp/XpTrackerService.java | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java b/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java index 0dc3aff491..4f3f276d3e 100644 --- a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java +++ b/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerController.java @@ -42,9 +42,9 @@ public class XpTrackerController private XpTrackerService xpTrackerService; @RequestMapping("/update") - public void update(@RequestParam String username) throws ExecutionException + public void update(@RequestParam String username) { - xpTrackerService.update(username); + xpTrackerService.tryUpdate(username); } @RequestMapping("/get") diff --git a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java b/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java index 2da8968fa2..d35d81fcf6 100644 --- a/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java +++ b/http-service/src/main/java/net/runelite/http/service/xp/XpTrackerService.java @@ -36,6 +36,7 @@ import net.runelite.http.service.xp.beans.PlayerEntity; import net.runelite.http.service.xp.beans.XpEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.sql2o.Connection; import org.sql2o.Sql2o; @@ -53,12 +54,19 @@ public class XpTrackerService @Autowired private HiscoreService hiscoreService; + private String nextUsername; + public void update(String username) throws ExecutionException { HiscoreResult hiscoreResult = hiscoreService.lookupUsername(username, HiscoreEndpoint.NORMAL); update(username, hiscoreResult); } + public void tryUpdate(String username) + { + nextUsername = username; + } + public void update(String username, HiscoreResult hiscoreResult) { try (Connection con = sql2o.open()) @@ -189,4 +197,19 @@ public class XpTrackerService return findXpAtTime(con, username, time); } } + + @Scheduled(fixedDelay = 3000) + public void update() throws ExecutionException + { + String next = nextUsername; + nextUsername = null; + + if (next == null) + { + return; + } + + HiscoreResult hiscoreResult = hiscoreService.lookupUsername(next, HiscoreEndpoint.NORMAL); + update(next, hiscoreResult); + } }