Add total number of encrypted/validated groups to the keys page

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent 6cf9eb5043
commit 6c728d758c
  1. 35
      archive/src/main/kotlin/org/openrs2/archive/key/KeyExporter.kt
  2. 4
      archive/src/main/kotlin/org/openrs2/archive/web/KeysController.kt
  3. 17
      archive/src/main/resources/org/openrs2/archive/templates/keys/index.html

@ -9,8 +9,35 @@ import javax.inject.Singleton
public class KeyExporter @Inject constructor( public class KeyExporter @Inject constructor(
private val database: Database private val database: Database
) { ) {
public suspend fun count(): Pair<Long, Long> { 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 -> 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( connection.prepareStatement(
""" """
SELECT SELECT
@ -23,9 +50,9 @@ public class KeyExporter @Inject constructor(
stmt.executeQuery().use { rows -> stmt.executeQuery().use { rows ->
check(rows.next()) check(rows.next())
val all = rows.getLong(1) val allKeys = rows.getLong(1)
val valid = rows.getLong(2) val validKeys = rows.getLong(2)
Pair(all, valid) Stats(allKeys, validKeys, encryptedGroups, validGroups)
} }
} }
} }

@ -12,8 +12,8 @@ public class KeysController @Inject constructor(
private val exporter: KeyExporter private val exporter: KeyExporter
) { ) {
public suspend fun index(call: ApplicationCall) { public suspend fun index(call: ApplicationCall) {
val (all, valid) = exporter.count() val stats = exporter.count()
call.respond(ThymeleafContent("keys/index.html", mapOf("all" to all, "valid" to valid))) call.respond(ThymeleafContent("keys/index.html", mapOf("stats" to stats)))
} }
public suspend fun exportAll(call: ApplicationCall) { public suspend fun exportAll(call: ApplicationCall) {

@ -11,10 +11,21 @@
<nav th:replace="layout.html :: nav(active='keys')"></nav> <nav th:replace="layout.html :: nav(active='keys')"></nav>
<main class="container"> <main class="container">
<h1>Keys</h1> <h1>Keys</h1>
<!--/*@thymesVar id="stats" type="org.openrs2.archive.key.KeyExporter.Stats"*/-->
<p> <p>
There are <strong th:text="${#numbers.formatInteger(all, 1, 'COMMA')}">0</strong> candidate keys in There are
the database, of which <strong th:text="${#numbers.formatInteger(valid, 1, 'COMMA')}">0</strong> have <strong th:text="${#numbers.formatInteger(stats.allKeys, 1, 'COMMA')}">0</strong>
been validated against at least one encrypted group. candidate keys in the database, of which
<strong th:text="${#numbers.formatInteger(stats.validKeys, 1, 'COMMA')}">0</strong>
have been validated against at least one encrypted group.
</p>
<p>
There are
<strong th:text="${#numbers.formatInteger(stats.encryptedGroups, 1, 'COMMA')}">0</strong>
encrypted groups in the database, of which
<strong th:text="${#numbers.formatInteger(stats.validGroups, 1, 'COMMA')}">0</strong>
have a validated key. This is equal to the total number of
validated keys if and only if keys are not re-used.
</p> </p>
<h2>Download</h2> <h2>Download</h2>
<p> <p>

Loading…
Cancel
Save