From 560fce9b01c8d952ddea304d04ec6b34f024a78d Mon Sep 17 00:00:00 2001 From: Liam Date: Thu, 1 Aug 2024 01:22:13 +0100 Subject: [PATCH] meow --- .../platform/impl/ScoreSaberPlatform.java | 16 +--------------- .../couchdb/TrackedScoreRepository.java | 7 +++++++ .../fascinated/services/TrackedScoreService.java | 1 + 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java b/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java index 58fe085..d070ad2 100644 --- a/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java +++ b/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java @@ -195,22 +195,8 @@ public class ScoreSaberPlatform extends Platform { this.getPlatform().getPlatformName() ); - int finished = 0; - - // Delete duplicated score ids - List 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 + int finished = 0; for (String id : uniqueLeaderboardIds) { try { ScoreSaberLeaderboardToken leaderboard = this.scoreSaberService.getLeaderboard(id, true); // Update the cached leaderboard diff --git a/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java b/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java index 8d1624f..26f7aac 100644 --- a/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java +++ b/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java @@ -13,6 +13,13 @@ import java.util.List; * @author Fascinated (fascinated7) */ public interface TrackedScoreRepository extends CrudRepository { + /** + * Ensures that the deduplication of the scores is done. + */ + @Modifying @Transactional + @Query(value = "ALTER TABLE score DEDUP ENABLE UPSERT KEYS(timestamp, score_id)", nativeQuery = true) + void ensureDeduplication(); + /** * Updates the pp of a score. * diff --git a/src/main/java/cc/fascinated/services/TrackedScoreService.java b/src/main/java/cc/fascinated/services/TrackedScoreService.java index c613b2d..3afca8f 100644 --- a/src/main/java/cc/fascinated/services/TrackedScoreService.java +++ b/src/main/java/cc/fascinated/services/TrackedScoreService.java @@ -31,6 +31,7 @@ public class TrackedScoreService { @Autowired public TrackedScoreService(@NonNull TrackedScoreRepository trackedScoreRepository) { this.trackedScoreRepository = trackedScoreRepository; + this.trackedScoreRepository.ensureDeduplication(); } /**