add missing leaderboards
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 37s

This commit is contained in:
Lee 2024-08-01 02:13:34 +01:00
parent 4e828f2c2b
commit 58bdc6f414
2 changed files with 37 additions and 34 deletions

@ -33,7 +33,7 @@ public class ScoreSaberPlatform extends Platform {
/**
* Delay in ms for requests per minute.
*/
private static final long UPDATE_DELAY = 1000L / 150L; // 150 requests per minute
private static final long UPDATE_DELAY = 1000L / 250L; // 150 requests per minute
/**
* The base multiplier for stars.
@ -192,21 +192,31 @@ public class ScoreSaberPlatform extends Platform {
public void updateLeaderboards() {
// TODO: PUSH THIS
List<TrackedScore> scores = this.trackedScoreService.getTrackedScores(this.getPlatform(), true);
Map<String, ScoreSaberLeaderboardToken> rankedLeaderboards = new HashMap<>();
Map<String, ScoreSaberLeaderboardToken> leaderboards = new HashMap<>();
for (ScoreSaberLeaderboardPageToken rankedLeaderboard : this.scoreSaberService.getRankedLeaderboards()) {
for (ScoreSaberLeaderboardToken leaderboard : rankedLeaderboard.getLeaderboards()) {
rankedLeaderboards.put(leaderboard.getId(), leaderboard);
leaderboards.put(leaderboard.getId(), leaderboard);
}
}
// Add any missing leaderboards
for (TrackedScore score : scores) {
if (leaderboards.containsKey(score.getLeaderboardId())) {
continue;
}
ScoreSaberLeaderboardToken leaderboard = this.scoreSaberService.getLeaderboard(score.getLeaderboardId(), true);
leaderboards.put(leaderboard.getId(), leaderboard);
}
log.info("Updating {} leaderboards for platform '{}'",
rankedLeaderboards.size(),
leaderboards.size(),
this.getPlatform().getPlatformName()
);
// Update the leaderboards
int finished = 0;
for (Map.Entry<String, ScoreSaberLeaderboardToken> leaderboardEntry : rankedLeaderboards.entrySet()) {
for (Map.Entry<String, ScoreSaberLeaderboardToken> leaderboardEntry : leaderboards.entrySet()) {
String id = leaderboardEntry.getKey();
ScoreSaberLeaderboardToken leaderboard = leaderboardEntry.getValue();
@ -220,11 +230,6 @@ public class ScoreSaberPlatform extends Platform {
}
try {
if (leaderboard == null) {
log.warn("Failed to update leaderboard '{}' for platform '{}'", id, this.getPlatform().getPlatformName());
continue;
}
List<TrackedScore> toUpdate = scores.stream().filter(score -> {
if (!score.getLeaderboardId().equals(id)) { // Check if the leaderboard ID matches
return false;
@ -246,14 +251,13 @@ public class ScoreSaberPlatform extends Platform {
}
finished++;
log.info("Updated leaderboard '{}' for platform '{}', changed {} scores. ({}/{})",
leaderboard.getSongName(),
this.getPlatform().getPlatformName(),
toUpdate.size(),
finished,
rankedLeaderboards.size()
);
if (finished % 100 == 0) {
log.info("Updated {}/{} leaderboards for platform '{}'",
finished,
leaderboards.size(),
this.getPlatform().getPlatformName()
);
}
} catch (Exception ex) {
log.error("An error occurred while updating leaderboard '{}'", id, ex);
}

@ -30,16 +30,8 @@ public class PlatformService {
*/
private final List<Platform> platforms = new ArrayList<>();
/**
* The tracked score repository to use.
*/
@NonNull
private final TrackedScoreRepository trackedScoreRepository;
@Autowired
public PlatformService(@NonNull ApplicationContext context, @NonNull TrackedScoreRepository trackedScoreRepository) {
this.trackedScoreRepository = trackedScoreRepository;
public PlatformService(@NonNull ApplicationContext context) {
log.info("Registering platforms...");
registerPlatform(context.getBean(ScoreSaberPlatform.class));
log.info("Loaded %s platforms.".formatted(this.platforms.size()));
@ -123,17 +115,24 @@ public class PlatformService {
Document finalDocument = document;
EXECUTOR_SERVICE.execute(() -> {
platform.updateLeaderboards();
// Update the document
finalDocument.put("currentCurveVersion", platform.getCurrentCurveVersion());
MongoService.INSTANCE.getPlatformsCollection().replaceOne(Filters.eq("_id", platform.getPlatform().getPlatformName()), finalDocument);
this.savePlatform(platform, finalDocument);
}); // Update the leaderboards
} else {
// Update the document
document.put("currentCurveVersion", platform.getCurrentCurveVersion());
MongoService.INSTANCE.getPlatformsCollection().replaceOne(Filters.eq("_id", platform.getPlatform().getPlatformName()), document);
this.savePlatform(platform, document);
}
}
/**
* Saves the platform.
*
* @param platform the platform to save
* @param document the document to save
*/
public void savePlatform(Platform platform, Document document) {
document.put("currentCurveVersion", platform.getCurrentCurveVersion());
MongoService.INSTANCE.getPlatformsCollection().replaceOne(Filters.eq("_id", platform.getPlatform().getPlatformName()), document);
}
/**
* Gets the ScoreSaber platform.
*