SteamWar/BungeeCore
Archiviert
13
2

Update UserElo.gameModeUserEloCache
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
yoyosource 2022-03-11 13:31:38 +01:00
Ursprung 0b452d30c3
Commit 2923d249db

Datei anzeigen

@ -20,8 +20,6 @@
package de.steamwar.bungeecore.sql;
import de.steamwar.bungeecore.ArenaMode;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import java.util.HashMap;
import java.util.Map;
@ -33,17 +31,10 @@ public class UserElo {
public static final int ELO_DEFAULT = 1000;
private static final Map<Key, Optional<Integer>> userEloCache = new HashMap<>();
private static final Map<String, Map<Integer, Optional<Integer>>> gameModeUserEloCache = new HashMap<>();
private static final Map<String, Integer> maxEloCache = new HashMap<>();
private static final Map<Integer, String> emblemCache = new HashMap<>();
@AllArgsConstructor
@EqualsAndHashCode
private static class Key {
private final int userId;
private final String gameMode;
}
private static final Statement elo = new Statement("SELECT UserElo FROM Elo WHERE UserID = ? AND GameMode = ? AND Season = ?");
private static final Statement setElo = new Statement("UPDATE UserELo SET Elo = ? WHERE Season = ? AND UserID = ? AND GameMode = ?");
private static final Statement place = new Statement("SELECT COUNT(*) AS Place FROM UserElo WHERE GameMode = ? AND Elo > ? AND Season = ?");
@ -51,8 +42,9 @@ public class UserElo {
private static final Statement fightsOfSeason = new Statement("SELECT COUNT(*) AS Fights FROM FightPlayer INNER JOIN Fight F on FightPlayer.FightID = F.FightID WHERE UserID = ? AND GameMode = ? AND UNIX_TIMESTAMP(StartTime) + Duration >= UNIX_TIMESTAMP(?)");
public static Optional<Integer> getElo(int userID, String gameMode) {
Key key = new Key(userID, gameMode);
return userEloCache.computeIfAbsent(key, k -> {
return gameModeUserEloCache.computeIfAbsent(gameMode, gm -> {
return new HashMap<>();
}).computeIfAbsent(userID, uid -> {
return elo.select(rs -> {
if (rs.next())
return Optional.of(rs.getInt("Elo"));
@ -81,8 +73,7 @@ public class UserElo {
public static void setElo(int userId, String gameMode, int elo) {
emblemCache.remove(userId);
Key key = new Key(userId, gameMode);
userEloCache.put(key, Optional.of(elo));
gameModeUserEloCache.computeIfAbsent(gameMode, gm -> new HashMap<>()).put(userId, Optional.of(elo));
maxEloCache.compute(gameMode, (gm, max) -> {
if (max == null || max < elo) {
emblemCache.clear();
@ -140,7 +131,7 @@ public class UserElo {
}
public static void clearCache() {
userEloCache.clear();
gameModeUserEloCache.clear();
maxEloCache.clear();
emblemCache.clear();
}