xp tracker: try to not look up the same user too frequently
This commit is contained in:
@@ -24,6 +24,9 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.xp;
|
package net.runelite.http.service.xp;
|
||||||
|
|
||||||
|
import com.google.common.hash.BloomFilter;
|
||||||
|
import com.google.common.hash.Funnels;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@@ -54,6 +57,7 @@ public class XpTrackerService
|
|||||||
@Autowired
|
@Autowired
|
||||||
private HiscoreService hiscoreService;
|
private HiscoreService hiscoreService;
|
||||||
|
|
||||||
|
private BloomFilter<String> usernameFilter = createFilter();
|
||||||
private String nextUsername;
|
private String nextUsername;
|
||||||
|
|
||||||
public void update(String username) throws ExecutionException
|
public void update(String username) throws ExecutionException
|
||||||
@@ -64,7 +68,13 @@ public class XpTrackerService
|
|||||||
|
|
||||||
public void tryUpdate(String username)
|
public void tryUpdate(String username)
|
||||||
{
|
{
|
||||||
|
if (nextUsername != null || usernameFilter.mightContain(username))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nextUsername = username;
|
nextUsername = username;
|
||||||
|
usernameFilter.put(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(String username, HiscoreResult hiscoreResult)
|
public void update(String username, HiscoreResult hiscoreResult)
|
||||||
@@ -212,4 +222,18 @@ public class XpTrackerService
|
|||||||
HiscoreResult hiscoreResult = hiscoreService.lookupUsername(next, HiscoreEndpoint.NORMAL);
|
HiscoreResult hiscoreResult = hiscoreService.lookupUsername(next, HiscoreEndpoint.NORMAL);
|
||||||
update(next, hiscoreResult);
|
update(next, hiscoreResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(fixedDelay = 60 * 60 * 1000) // one hour
|
||||||
|
public void clearFilter()
|
||||||
|
{
|
||||||
|
usernameFilter = createFilter();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BloomFilter<String> createFilter()
|
||||||
|
{
|
||||||
|
return BloomFilter.create(
|
||||||
|
Funnels.stringFunnel(Charset.defaultCharset()),
|
||||||
|
100_000
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user