From f923a007a7c5a2d0fcc4588f2b4e4e5c15874480 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Fri, 14 Nov 2025 23:24:48 +0100 Subject: [PATCH] Revert "Add EventCache for efficient retrieval of event groups and teams" This reverts commit 8b4f864f998b035a862e17a0c3e236162aab6cda. Revert "Refactor EventFights and Fight classes to improve player initialization and retrieval" This reverts commit 8d705e7a847861ab5ce6fadf399705e82993e58f. Revert "Refactor EventFights and Fight classes to improve player initialization and retrieval" This reverts commit 78352a3e67b6e42b04a6688c3809301ccfd7fb28. --- CommonCore/SQL/src/de/steamwar/sql/Fight.kt | 2 +- .../SQL/src/de/steamwar/sql/FightPlayer.kt | 6 --- CommonCore/SQL/src/de/steamwar/sql/Team.kt | 4 +- .../src/de/steamwar/data/EventCache.kt | 36 ------------- .../src/de/steamwar/routes/EventFights.kt | 50 +++---------------- .../src/de/steamwar/routes/Events.kt | 7 ++- 6 files changed, 12 insertions(+), 93 deletions(-) delete mode 100644 WebsiteBackend/src/de/steamwar/data/EventCache.kt diff --git a/CommonCore/SQL/src/de/steamwar/sql/Fight.kt b/CommonCore/SQL/src/de/steamwar/sql/Fight.kt index 58779556..d64d7583 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Fight.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/Fight.kt @@ -141,7 +141,7 @@ class Fight(id: EntityID) : IntEntity(id) { lateinit var bluePlayers: List lateinit var redPlayers: List - fun initPlayers(fightPlayers: List) { + private fun initPlayers(fightPlayers: List) { val blue = mutableListOf() val red = mutableListOf() diff --git a/CommonCore/SQL/src/de/steamwar/sql/FightPlayer.kt b/CommonCore/SQL/src/de/steamwar/sql/FightPlayer.kt index c7a3ea15..d0238c96 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/FightPlayer.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/FightPlayer.kt @@ -23,7 +23,6 @@ import de.steamwar.sql.internal.useDb import org.jetbrains.exposed.v1.core.dao.id.CompositeID import org.jetbrains.exposed.v1.core.dao.id.CompositeIdTable import org.jetbrains.exposed.v1.core.dao.id.EntityID -import org.jetbrains.exposed.v1.core.eq import org.jetbrains.exposed.v1.core.inList import org.jetbrains.exposed.v1.dao.CompositeEntity import org.jetbrains.exposed.v1.dao.CompositeEntityClass @@ -68,11 +67,6 @@ class FightPlayer(id: EntityID) : CompositeEntity(id) { fun batchGet(fightIds: List) = useDb { find { FightPlayerTable.fightId inList fightIds.toList() }.toList() } - - @JvmStatic - fun getFight(fightId: Int) = useDb { - find { FightPlayerTable.fightId eq fightId }.toList() - } } val fightID by FightPlayerTable.fightId.transform({ EntityID(it, FightTable) }, { it.value }) diff --git a/CommonCore/SQL/src/de/steamwar/sql/Team.kt b/CommonCore/SQL/src/de/steamwar/sql/Team.kt index 2738170b..0c56a656 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/Team.kt +++ b/CommonCore/SQL/src/de/steamwar/sql/Team.kt @@ -43,10 +43,10 @@ class Team(id: EntityID) : IntEntity(id) { private val teamCache = mutableMapOf() @JvmStatic - fun clear() = synchronized(teamCache) { teamCache.clear() } + fun clear() = teamCache.clear() @JvmStatic - fun byId(id: Int) = synchronized(teamCache) { teamCache.computeIfAbsent(id) { useDb { Team[id] } } } + fun byId(id: Int) = teamCache.computeIfAbsent(id) { useDb { Team[id] } } @JvmStatic fun get(name: String) = useDb { find { TeamTable.name.lowerCase() eq name.lowercase() or (TeamTable.kuerzel.lowerCase() eq name.lowercase()) }.firstOrNull() } diff --git a/WebsiteBackend/src/de/steamwar/data/EventCache.kt b/WebsiteBackend/src/de/steamwar/data/EventCache.kt deleted file mode 100644 index cbdc1e4f..00000000 --- a/WebsiteBackend/src/de/steamwar/data/EventCache.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.data - -import de.steamwar.routes.ResponseGroups -import de.steamwar.routes.ResponseTeam -import de.steamwar.sql.EventGroup -import de.steamwar.sql.Team - -class EventCache { - private val groupCache = mutableMapOf() - private val teamCache = mutableMapOf() - - fun getGroup(id: Int): ResponseGroups = groupCache.getOrPut(id) { ResponseGroups(EventGroup.byId(id).get()) } - fun getTeam(id: Int): ResponseTeam = teamCache.getOrPut(id) { ResponseTeam(Team.byId(id)) } - - fun convertGroup(group: EventGroup) = ResponseGroups(group).also { groupCache[group.getId()] = it } - fun convertTeam(team: Team) = ResponseTeam(team).also { teamCache[team.teamId] = it } -} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt index 504cb3c1..82569d40 100644 --- a/WebsiteBackend/src/de/steamwar/routes/EventFights.kt +++ b/WebsiteBackend/src/de/steamwar/routes/EventFights.kt @@ -20,9 +20,7 @@ package de.steamwar.routes import de.steamwar.ResponseError -import de.steamwar.data.EventCache import de.steamwar.sql.* -import de.steamwar.sql.internal.useDb import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.request.* @@ -43,55 +41,19 @@ data class ResponseEventFight( val ergebnis: Int, val spectatePort: Int?, val group: ResponseGroups?, - val hasFinished: Boolean, - val fightData: FightData? = null + val hasFinished: Boolean ) { - constructor(eventFight: EventFight, cache: EventCache = EventCache()) : this( + constructor(eventFight: EventFight) : this( eventFight.fightID, eventFight.spielmodus, eventFight.map, - cache.getTeam(eventFight.teamBlue), - cache.getTeam(eventFight.teamRed), + ResponseTeam(Team.byId(eventFight.teamBlue)), + ResponseTeam(Team.byId(eventFight.teamRed)), eventFight.startTime.time, eventFight.ergebnis, eventFight.spectatePort, - eventFight.groupId?.let { cache.getGroup(it.value) }, - eventFight.hasFinished(), - eventFight.fight?.let { FightData(Fight.getById(it)) } - ) -} - -@Serializable -data class FightData( - val id: Int, - val gamemode: String, - val server: String, - val start: Long, - val duration: Int, - val blueLeader: ResponseUser, - val redLeader: ResponseUser, - val blueSchem: String?, - val redSchem: String?, - val win: String, - val winCondition: String, - - val bluePlayers: List, - val redPlayers: List, -) { - constructor(fight: Fight, players: List = FightPlayer.getFight(fight.fightID)) : this( - fight.id.value, - fight.gameMode, - fight.server, - fight.startTime.time, - fight.duration, - ResponseUser.get(fight.blueLeader), - ResponseUser.get(fight.redLeader), - fight.blueSchem?.let { SchematicNode.getSchematicNode(it.value)?.name }, - fight.redSchem?.let { SchematicNode.getSchematicNode(it.value)?.name }, - fight.winner.name, - fight.winCondition, - players.filter { it.team == 1 }.map { ResponseUser.get(it.userID) }, - players.filter { it.team == 2 }.map { ResponseUser.get(it.userID) }, + eventFight.group.orElse(null)?.let { ResponseGroups(it, short = true) }, + eventFight.hasFinished() ) } diff --git a/WebsiteBackend/src/de/steamwar/routes/Events.kt b/WebsiteBackend/src/de/steamwar/routes/Events.kt index 1ad54aa2..e82fc495 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Events.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Events.kt @@ -20,7 +20,6 @@ package de.steamwar.routes import de.steamwar.ResponseError -import de.steamwar.data.EventCache import de.steamwar.plugins.SWPermissionCheck import de.steamwar.sql.* import de.steamwar.sql.EventGroup.EventGroupType @@ -114,10 +113,10 @@ data class ExtendedResponseEvent( val referees: List, val relations: List ) { - constructor(event: Event, cache: EventCache = EventCache()) : this( + constructor(event: Event) : this( ResponseEvent(event), - TeamTeilnahme.getTeams(event.eventID).map { cache.convertTeam(it) }, - EventGroup.get(event).map { cache.convertGroup(it) }, + TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) }, + EventGroup.get(event).map { ResponseGroups(it) }, EventFight.getEvent(event.eventID).map { ResponseEventFight(it) }, Referee.get(event.eventID).map { ResponseUser.get(SteamwarUser.byId(it)!!) }, EventRelation.get(event).map { ResponseRelation(it) }