Add total size of all caches to the caches page

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 2 years ago
parent 2d7b235f15
commit 0814443bc5
  1. 19
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt
  2. 10
      archive/src/main/kotlin/org/openrs2/archive/web/CachesController.kt
  3. 4
      archive/src/main/resources/org/openrs2/archive/templates/caches/index.html

@ -199,6 +199,25 @@ public class CacheExporter @Inject constructor(
val key: XteaKey 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<CacheSummary> { public suspend fun list(): List<CacheSummary> {
return database.execute { connection -> return database.execute { connection ->
connection.prepareStatement( connection.prepareStatement(

@ -50,7 +50,15 @@ public class CachesController @Inject constructor(
public suspend fun index(call: ApplicationCall) { public suspend fun index(call: ApplicationCall) {
val caches = exporter.list() 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) { public suspend fun indexJson(call: ApplicationCall) {

@ -110,6 +110,10 @@
</tbody> </tbody>
</table> </table>
</div> </div>
<p>
The total size of all caches in the archive is
<strong th:text="${#byteunits.format(totalSize)}">0 B</strong>.
</p>
<p> <p>
<sup id="empty-locs">1</sup> Map squares in the middle of the <sup id="empty-locs">1</sup> Map squares in the middle of the
sea are unreachable by normal players, making it impossible to sea are unreachable by normal players, making it impossible to

Loading…
Cancel
Save