api: don't fetch all data when tracking player metrics
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 30s

This commit is contained in:
Lee 2024-08-05 04:25:34 +01:00
parent 6f49d81664
commit 84eb8a4b94
3 changed files with 7 additions and 7 deletions

@ -145,10 +145,10 @@ public class ScoreSaberPlatform extends Platform {
@Override
public void trackPlayerMetrics() {
Date date = DateUtils.getMidnightToday();
for (User user : this.userService.getUsers(false)) {
for (User user : this.userService.getUsers(true)) {
HistoryPoint history = user.getHistory().getHistoryForDate(date);
if (user.isLinkedAccount()) { // Check if the user has linked their account
ScoreSaberAccountToken account = scoreSaberService.getAccount(user); // Get the account from the ScoreSaber API
ScoreSaberAccountToken account = this.scoreSaberService.getAccount(user); // Get the account from the ScoreSaber API
history.setPp(account.getPp());
history.setRank(account.getRank());
history.setCountryRank(account.getCountryRank());

@ -25,8 +25,8 @@ public interface UserRepository extends MongoRepository<User, UUID> {
*
* @return the list of users
*/
@Query(value = "{}", fields = "{ 'steamId' : 1 }")
List<User> fetchOnlySteamIds();
@Query(value = "{}", fields = "{ 'steamId' : 1, linkedAccount: 1 }")
List<User> fetchAccountsSimple();
/**
* Finds a user by their username.

@ -105,9 +105,9 @@ public class UserService {
*
* @return all users
*/
public List<User> getUsers(boolean steamIdsOnly) {
if (steamIdsOnly) {
return this.userRepository.fetchOnlySteamIds();
public List<User> getUsers(boolean smallerAccount) {
if (smallerAccount) {
return this.userRepository.fetchAccountsSimple();
}
return this.userRepository.findAll();
}