xp tracker: limit to one update per 5 minutes
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.service.xp;
|
package net.runelite.http.service.xp;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -43,6 +44,8 @@ import org.sql2o.Sql2o;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class XpTrackerService
|
public class XpTrackerService
|
||||||
{
|
{
|
||||||
|
private static final Duration UPDATE_TIME = Duration.ofMinutes(5);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("Runelite XP Tracker SQL2O")
|
@Qualifier("Runelite XP Tracker SQL2O")
|
||||||
private Sql2o sql2o;
|
private Sql2o sql2o;
|
||||||
@@ -62,7 +65,8 @@ public class XpTrackerService
|
|||||||
{
|
{
|
||||||
PlayerEntity playerEntity = findOrCreatePlayer(con, username);
|
PlayerEntity playerEntity = findOrCreatePlayer(con, username);
|
||||||
|
|
||||||
XpEntity currentXp = findXpAtTime(con, username, Instant.now());
|
Instant now = Instant.now();
|
||||||
|
XpEntity currentXp = findXpAtTime(con, username, now);
|
||||||
if (currentXp != null)
|
if (currentXp != null)
|
||||||
{
|
{
|
||||||
XpData hiscoreData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
|
XpData hiscoreData = XpMapper.INSTANCE.hiscoreResultToXpData(hiscoreResult);
|
||||||
@@ -73,6 +77,13 @@ public class XpTrackerService
|
|||||||
log.debug("Hiscore for {} already up to date", username);
|
log.debug("Hiscore for {} already up to date", username);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Duration difference = Duration.between(currentXp.getTime(), now);
|
||||||
|
if (difference.compareTo(UPDATE_TIME) <= 0)
|
||||||
|
{
|
||||||
|
log.debug("Updated {} too recently", username);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
con.createQuery("insert into xp (player,attack_xp,defence_xp,strength_xp,hitpoints_xp,ranged_xp,prayer_xp,magic_xp,cooking_xp,woodcutting_xp,"
|
con.createQuery("insert into xp (player,attack_xp,defence_xp,strength_xp,hitpoints_xp,ranged_xp,prayer_xp,magic_xp,cooking_xp,woodcutting_xp,"
|
||||||
|
|||||||
Reference in New Issue
Block a user