fix
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 41s

This commit is contained in:
Lee 2024-08-01 01:10:08 +01:00
parent 1efab2ed08
commit 09834e9eac
2 changed files with 27 additions and 3 deletions

View File

@ -187,7 +187,7 @@ public class ScoreSaberPlatform extends Platform {
@Override
public void updateLeaderboards() {
List<TrackedScore> scores = this.trackedScoreService.getTrackedScores(this.getPlatform(), true);
List<TrackedScore> scores = this.trackedScoreService.getTrackedScores(this.getPlatform(), false);
List<String> leaderboardIds = scores.stream().map(TrackedScore::getLeaderboardId).toList();
log.info("Updating {} leaderboards for platform '{}'",
@ -197,6 +197,19 @@ public class ScoreSaberPlatform extends Platform {
int finished = 0;
// Delete duplicated score ids
List<TrackedScore> duplicatedScores = scores.stream().filter(score -> {
long count = scores.stream().filter(s -> s.getScoreId().equals(score.getScoreId())).count();
return count > 1;
}).toList();
if (!duplicatedScores.isEmpty()) {
this.trackedScoreService.deleteScores(duplicatedScores.toArray(TrackedScore[]::new));
log.info("Deleted {} duplicated scores for platform '{}'",
duplicatedScores.size(),
this.getPlatform().getPlatformName()
);
}
// Update the leaderboards
for (String id : leaderboardIds) {
try {

View File

@ -85,8 +85,8 @@ public class TrackedScoreService {
* @param platform the platform to get the scores from
* @return the tracked scores
*/
public List<TrackedScore> getTrackedScores(Platform.Platforms platform, boolean ranked) {
if (ranked) {
public List<TrackedScore> getTrackedScores(Platform.Platforms platform, boolean onlyRanked) {
if (onlyRanked) {
return trackedScoreRepository.findAllByPlatformRankedOnly(platform.getPlatformName());
}
return trackedScoreRepository.findAllByPlatform(platform.getPlatformName());
@ -102,4 +102,15 @@ public class TrackedScoreService {
this.trackedScoreRepository.updateScorePp(score.getScoreId(), score.getPp());
}
}
/**
* Deletes a list of tracked scores.
*
* @param scores the scores to delete
*/
public void deleteScores(TrackedScore... scores) {
for (TrackedScore score : scores) {
this.trackedScoreRepository.delete(score);
}
}
}