Add EventCache for efficient retrieval of event groups and teams

Signed-off-by: Chaoscaot <max@maxsp.de>
This commit is contained in:
2025-11-14 22:47:27 +01:00
parent f9cb712b07
commit 8b4f864f99
3 changed files with 84 additions and 9 deletions
@@ -0,0 +1,36 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
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<Int, ResponseGroups>()
private val teamCache = mutableMapOf<Int, ResponseTeam>()
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 }
}