api: track player histories more often to keep them more up to date
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 1m4s

This commit is contained in:
Lee 2024-08-06 21:12:59 +01:00
parent 131a5c2efe
commit bd31254990
5 changed files with 31 additions and 6 deletions

@ -20,6 +20,9 @@ public class RootController {
@ResponseBody
@GetMapping(value = "/")
public ResponseEntity<?> getWelcome() {
return ResponseEntity.ok(Map.of("message", "Hello!"));
return ResponseEntity.ok(Map.of(
"message", "Hello!",
"url", "https://git.fascinated.cc/Fascinated/beatsaber-scoretracker"
));
}
}

@ -1,6 +1,9 @@
package cc.fascinated.model.user;
import cc.fascinated.model.user.history.History;
import cc.fascinated.model.user.history.HistoryPoint;
import cc.fascinated.platform.Platform;
import cc.fascinated.services.ScoreService;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
@ -77,6 +80,25 @@ public class User {
return this.history;
}
/**
* Gets the user's today history.
*
* @return the user's today history
*/
public HistoryPoint getTodayHistory() {
HistoryPoint todayHistory = this.getHistory().getTodayHistory();
if (todayHistory.getTotalPlayCount() == null) {
todayHistory.setTotalPlayCount(ScoreService.INSTANCE.getTotalScores(Platform.Platforms.SCORESABER, this));
}
if (todayHistory.getTotalRankedPlayCount() == null) {
todayHistory.setTotalRankedPlayCount(ScoreService.INSTANCE.getTotalRankedScores(Platform.Platforms.SCORESABER, this));
}
if (todayHistory.getTotalUnrankedPlayCount() == null) {
todayHistory.setTotalUnrankedPlayCount(ScoreService.INSTANCE.getTotalUnrankedScores(Platform.Platforms.SCORESABER, this));
}
return todayHistory;
}
/**
* Gets the user as a DTO.
*

@ -58,10 +58,10 @@ public class PlatformService {
/**
* Updates the platform players.
* <p>
* This method is scheduled to run every day at 23:59.
* This method is scheduled to run every hour.
* </p>
*/
@Scheduled(cron = "0 59 23 * * *")
@Scheduled(cron = "0 0 * * * *")
public void updatePlayerMetrics() {
log.info("Updating %s platform player metrics...".formatted(this.platforms.size()));
for (Platform platform : this.platforms) {

@ -193,7 +193,7 @@ public class ScoreService {
}
ScoreSaberScore scoreSaberScore = new ScoreSaberScore(
counterService.getNext(CounterService.CounterType.SCORE),
this.counterService.getNext(CounterService.CounterType.SCORE),
user.getSteamId(),
Platform.Platforms.SCORESABER,
score.getId(),
@ -245,7 +245,7 @@ public class ScoreService {
* @param score The score to save.
*/
public void saveScore(User user, Score score) {
HistoryPoint todayHistory = user.getHistory().getTodayHistory();
HistoryPoint todayHistory = user.getTodayHistory();
if (score.isRanked()) {
todayHistory.incrementRankedPlayCount();
} else {

@ -94,7 +94,7 @@ public class UserService {
user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account
user.setUsername(accountToken.getName()); // Update the username
HistoryPoint historyToday = user.getHistory().getTodayHistory();
HistoryPoint historyToday = user.getTodayHistory();
historyToday.setRank(accountToken.getRank());
historyToday.setCountryRank(accountToken.getCountryRank());
historyToday.setPp(accountToken.getPp());