From 0814443bc5347fe5690aa34bf0995f5f9834e6ee Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 29 Oct 2022 15:30:08 +0100 Subject: [PATCH] Add total size of all caches to the caches page Signed-off-by: Graham --- .../openrs2/archive/cache/CacheExporter.kt | 19 +++++++++++++++++++ .../openrs2/archive/web/CachesController.kt | 10 +++++++++- .../archive/templates/caches/index.html | 4 ++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt index 2ba30504ae..cc3c969e5d 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt @@ -199,6 +199,25 @@ public class CacheExporter @Inject constructor( val key: XteaKey ) + public suspend fun totalSize(): Long { + return database.execute { connection -> + connection.prepareStatement( + """ + SELECT SUM(size) + FROM cache_stats + """.trimIndent() + ).use { stmt -> + stmt.executeQuery().use { rows -> + if (rows.next()) { + rows.getLong(1) + } else { + 0 + } + } + } + } + } + public suspend fun list(): List { return database.execute { connection -> connection.prepareStatement( diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt index 20f5478b89..e835895ead 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt @@ -50,7 +50,15 @@ public class CachesController @Inject constructor( public suspend fun index(call: ApplicationCall) { val caches = exporter.list() - call.respond(ThymeleafContent("caches/index.html", mapOf("caches" to caches))) + val totalSize = exporter.totalSize() + call.respond( + ThymeleafContent( + "caches/index.html", mapOf( + "caches" to caches, + "totalSize" to totalSize + ) + ) + ) } public suspend fun indexJson(call: ApplicationCall) { diff --git a/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html b/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html index 7174524644..188a812636 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/caches/index.html @@ -110,6 +110,10 @@ +

+ The total size of all caches in the archive is + 0 B. +

1 Map squares in the middle of the sea are unreachable by normal players, making it impossible to