diff --git a/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt b/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt index 30da09d6..56f235f6 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt @@ -9,8 +9,35 @@ import javax.inject.Singleton public class KeyExporter @Inject constructor( private val database: Database ) { - public suspend fun count(): Pair { + public data class Stats( + val allKeys: Long, + val validKeys: Long, + val encryptedGroups: Long, + val validGroups: Long + ) + + public suspend fun count(): Stats { return database.execute { connection -> + val encryptedGroups: Long + val validGroups: Long + + connection.prepareStatement( + """ + SELECT + COUNT(*), + COUNT(*) FILTER (WHERE c.key_id IS NOT NULL) + FROM containers c + WHERE c.encrypted + """.trimIndent() + ).use { stmt -> + stmt.executeQuery().use { rows -> + check(rows.next()) + + encryptedGroups = rows.getLong(1) + validGroups = rows.getLong(2) + } + } + connection.prepareStatement( """ SELECT @@ -23,9 +50,9 @@ public class KeyExporter @Inject constructor( stmt.executeQuery().use { rows -> check(rows.next()) - val all = rows.getLong(1) - val valid = rows.getLong(2) - Pair(all, valid) + val allKeys = rows.getLong(1) + val validKeys = rows.getLong(2) + Stats(allKeys, validKeys, encryptedGroups, validGroups) } } } diff --git a/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt b/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt index 4d692cf3..6025f0c5 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt @@ -12,8 +12,8 @@ public class KeysController @Inject constructor( private val exporter: KeyExporter ) { public suspend fun index(call: ApplicationCall) { - val (all, valid) = exporter.count() - call.respond(ThymeleafContent("keys/index.html", mapOf("all" to all, "valid" to valid))) + val stats = exporter.count() + call.respond(ThymeleafContent("keys/index.html", mapOf("stats" to stats))) } public suspend fun exportAll(call: ApplicationCall) { diff --git a/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html b/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html index ac33361e..9edf2aea 100644 --- a/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html +++ b/archive/src/main/resources/org/openrs2/archive/templates/keys/index.html @@ -11,10 +11,21 @@

Keys

+

- There are 0 candidate keys in - the database, of which 0 have - been validated against at least one encrypted group. + There are + 0 + candidate keys in the database, of which + 0 + have been validated against at least one encrypted group. +

+

+ There are + 0 + encrypted groups in the database, of which + 0 + have a validated key. This is equal to the total number of + validated keys if and only if keys are not re-used.

Download