From fa049455956e40efd126082c1eef470698263abb Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 3 Nov 2023 20:30:29 +0100 Subject: [PATCH] Updates --- build.gradle | 0 gradlew | 0 src/de/steamwar/sql/Fight.java | 1 - src/de/steamwar/sql/SteamwarUser.java | 52 --------------------------- src/de/steamwar/sql/Token.java | 2 ++ src/de/steamwar/sql/Tutorial.java | 1 - src/de/steamwar/sql/UserPerm.java | 3 ++ 7 files changed, 5 insertions(+), 54 deletions(-) mode change 100755 => 100644 build.gradle mode change 100755 => 100644 gradlew diff --git a/build.gradle b/build.gradle old mode 100755 new mode 100644 diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/src/de/steamwar/sql/Fight.java b/src/de/steamwar/sql/Fight.java index efa230d..f543be4 100644 --- a/src/de/steamwar/sql/Fight.java +++ b/src/de/steamwar/sql/Fight.java @@ -46,7 +46,6 @@ public class Fight { fight.initPlayers(fightPlayers); } - SteamwarUser.batchCache(fightPlayers.stream().map(FightPlayer::getUserID).collect(Collectors.toSet())); return fights; } diff --git a/src/de/steamwar/sql/SteamwarUser.java b/src/de/steamwar/sql/SteamwarUser.java index 3a9cfa5..dfdb5cf 100644 --- a/src/de/steamwar/sql/SteamwarUser.java +++ b/src/de/steamwar/sql/SteamwarUser.java @@ -59,50 +59,19 @@ public class SteamwarUser { private static final Statement getPlaytime = new Statement("SELECT SUM(UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime)) as Playtime FROM Session WHERE UserID = ?"); private static final Statement getFirstjoin = new Statement("SELECT MIN(StartTime) AS FirstJoin FROM Session WHERE UserID = ?"); - private static final Map usersById = new HashMap<>(); - private static final Map usersByUUID = new HashMap<>(); - private static final Map usersByName = new HashMap<>(); - private static final Map usersByDiscord = new HashMap<>(); - public static void clear() { - usersById.clear(); - usersByName.clear(); - usersByUUID.clear(); - usersByDiscord.clear(); - } - - public static void invalidate(int userId) { - SteamwarUser user = usersById.remove(userId); - if (user == null) - return; - usersByName.remove(user.getUserName()); - usersByUUID.remove(user.getUUID()); - usersByDiscord.remove(user.getDiscordId()); - } - public static SteamwarUser get(String userName){ - SteamwarUser user = usersByName.get(userName.toLowerCase()); - if(user != null) - return user; return byName.select(userName); } public static SteamwarUser get(UUID uuid){ - SteamwarUser user = usersByUUID.get(uuid); - if(user != null) - return user; return byUUID.select(uuid); } public static SteamwarUser get(int id) { - SteamwarUser user = usersById.get(id); - if(user != null) - return user; return byID.select(id); } public static SteamwarUser get(Long discordId) { - if(usersByDiscord.containsKey(discordId)) - return usersByDiscord.get(discordId); return byDiscord.select(discordId); } @@ -136,16 +105,6 @@ public class SteamwarUser { return byTeam.listSelect(teamId); } - public static void batchCache(Set ids) { - ids.removeIf(usersById::containsKey); - if(ids.isEmpty()) - return; - - try (SelectStatement batch = new SelectStatement<>(table, "SELECT * FROM UserData WHERE id IN (" + ids.stream().map(Object::toString).collect(Collectors.joining(", ")) + ")")) { - batch.listSelect(); - } - } - @Getter @Field(keys = {Table.PRIMARY}, autoincrement = true) private final int id; @@ -186,13 +145,6 @@ public class SteamwarUser { this.locale = locale; this.manualLocale = manualLocale; this.discordId = discordId != null && discordId != 0 ? discordId : null; - - usersById.put(id, this); - usersByName.put(userName.toLowerCase(), this); - usersByUUID.put(uuid, this); - if (this.discordId != null) { - usersByDiscord.put(discordId, this); - } } public UUID getUUID() { @@ -283,12 +235,8 @@ public class SteamwarUser { } public void setDiscordId(Long discordId) { - usersByDiscord.remove(this.discordId); this.discordId = discordId; updateDiscord.update(discordId, id); - if (discordId != null) { - usersByDiscord.put(discordId, this); - } } private void initPunishments() { diff --git a/src/de/steamwar/sql/Token.java b/src/de/steamwar/sql/Token.java index 5217f43..db34967 100644 --- a/src/de/steamwar/sql/Token.java +++ b/src/de/steamwar/sql/Token.java @@ -25,12 +25,14 @@ import de.steamwar.sql.internal.Statement; import de.steamwar.sql.internal.Table; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.ToString; import java.sql.Timestamp; import java.util.List; @AllArgsConstructor @Getter +@ToString public class Token { private static final Table table = new Table<>(Token.class); private static final Statement insert = table.insertFields(true, "Name", "Owner", "Hash"); diff --git a/src/de/steamwar/sql/Tutorial.java b/src/de/steamwar/sql/Tutorial.java index 9febcba..9d5c762 100644 --- a/src/de/steamwar/sql/Tutorial.java +++ b/src/de/steamwar/sql/Tutorial.java @@ -44,7 +44,6 @@ public class Tutorial { public static List getPage(int page, int elementsPerPage, boolean released) { List tutorials = by_popularity.listSelect(released, page * elementsPerPage, elementsPerPage); - SteamwarUser.batchCache(tutorials.stream().map(tutorial -> tutorial.creator).collect(Collectors.toSet())); return tutorials; } diff --git a/src/de/steamwar/sql/UserPerm.java b/src/de/steamwar/sql/UserPerm.java index 80a63dd..c23667a 100644 --- a/src/de/steamwar/sql/UserPerm.java +++ b/src/de/steamwar/sql/UserPerm.java @@ -82,8 +82,11 @@ public enum UserPerm { @Getter @AllArgsConstructor public static class Prefix { + private static int ordinalCounter = 0; + private final String colorCode; private final String chatPrefix; + private final int ordinal = ordinalCounter++; } @AllArgsConstructor