xp tracker: limit lookups to most 1 per 3 seconds

Drop the rest to prevent backlogging. The hiscore API throttling is
fairly strict.
This commit is contained in:
Adam
2018-12-20 14:04:15 -05:00
parent ee455e93dd
commit 1001ddf11b
2 changed files with 25 additions and 2 deletions

View File

@@ -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")

View File

@@ -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);
}
}