From 2923d249dbc602fa99aeae05ff76b8de3534e05d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 11 Mar 2022 13:31:38 +0100 Subject: [PATCH] Update UserElo.gameModeUserEloCache --- src/de/steamwar/bungeecore/sql/UserElo.java | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/de/steamwar/bungeecore/sql/UserElo.java b/src/de/steamwar/bungeecore/sql/UserElo.java index 8593cae1..ff49289e 100644 --- a/src/de/steamwar/bungeecore/sql/UserElo.java +++ b/src/de/steamwar/bungeecore/sql/UserElo.java @@ -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> userEloCache = new HashMap<>(); + private static final Map>> gameModeUserEloCache = new HashMap<>(); private static final Map maxEloCache = new HashMap<>(); private static final Map 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 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(); }