Add number of valid indexes, groups and keys to the web interface

Signed-off-by: Graham <gpe@openrs2.org>
Graham 4 years ago
parent 971fb642c1
commit 81e2dedee5
  1. 33
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt
  2. 25
      archive/src/main/resources/org/openrs2/archive/V1__init.sql
  3. 6
      archive/src/main/resources/org/openrs2/archive/templates/caches/index.html

@ -17,12 +17,17 @@ public class CacheExporter @Inject constructor(
private val database: Database, private val database: Database,
private val alloc: ByteBufAllocator private val alloc: ByteBufAllocator
) { ) {
public data class ArchiveStats(val indexes: Long, val validIndexes: Long)
public data class GroupStats(val groups: Long, val validGroups: Long, val keys: Long, val validKeys: Long)
public data class Cache( public data class Cache(
val id: Int, val id: Int,
val game: String, val game: String,
val build: Int?, val build: Int?,
val timestamp: Instant?, val timestamp: Instant?,
val name: String? val name: String?,
val archiveStats: ArchiveStats?,
val groupStats: GroupStats?
) )
public data class Key( public data class Key(
@ -38,10 +43,14 @@ public class CacheExporter @Inject constructor(
return database.execute { connection -> return database.execute { connection ->
connection.prepareStatement( connection.prepareStatement(
""" """
SELECT m.id, g.name, m.build, m.timestamp, m.name SELECT
m.id, g.name, m.build, m.timestamp, m.name,
a.indexes, a.valid_indexes, gs.groups, gs.valid_groups, gs.keys, gs.valid_keys
FROM master_indexes m FROM master_indexes m
JOIN games g ON g.id = m.game_id JOIN games g ON g.id = m.game_id
JOIN containers c ON c.id = m.container_id JOIN containers c ON c.id = m.container_id
LEFT JOIN master_index_archive_stats a ON a.master_index_id = m.id
LEFT JOIN master_index_group_stats gs ON gs.master_index_id = m.id
ORDER BY g.name ASC, m.build ASC, m.timestamp ASC ORDER BY g.name ASC, m.build ASC, m.timestamp ASC
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
@ -60,7 +69,25 @@ public class CacheExporter @Inject constructor(
val timestamp = rows.getTimestamp(4)?.toInstant() val timestamp = rows.getTimestamp(4)?.toInstant()
val name = rows.getString(5) val name = rows.getString(5)
caches += Cache(id, game, build, timestamp, name) val indexes = rows.getLong(6)
val archiveStats = if (!rows.wasNull()) {
val validIndexes = rows.getLong(7)
ArchiveStats(indexes, validIndexes)
} else {
null
}
val groups = rows.getLong(8)
val groupStats = if (!rows.wasNull()) {
val validGroups = rows.getLong(9)
val keys = rows.getLong(10)
val validKeys = rows.getLong(11)
GroupStats(groups, validGroups, keys, validKeys)
} else {
null
}
caches += Cache(id, game, build, timestamp, name, archiveStats, groupStats)
} }
caches caches

@ -153,4 +153,29 @@ JOIN groups g ON g.archive_id = i.archive_id AND g.group_id = ig.group_id AND (
(g.version = ig.version & 65535 AND g.version_truncated) (g.version = ig.version & 65535 AND g.version_truncated)
) )
JOIN containers c ON c.id = g.container_id AND c.crc32 = ig.crc32; JOIN containers c ON c.id = g.container_id AND c.crc32 = ig.crc32;
CREATE MATERIALIZED VIEW master_index_archive_stats (master_index_id, indexes, valid_indexes) AS
SELECT a.master_index_id, COUNT(*), COUNT(i.container_id)
FROM master_index_archives a
LEFT JOIN groups g ON g.archive_id = 255 AND g.group_id = a.archive_id::INTEGER AND
g.version = a.version AND NOT g.version_truncated
LEFT JOIN containers c ON c.id = g.container_id AND c.crc32 = a.crc32
LEFT JOIN indexes i ON i.container_id = g.container_id AND i.version = a.version
GROUP BY a.master_index_id;
CREATE UNIQUE INDEX ON master_index_archive_stats (master_index_id);
CREATE MATERIALIZED VIEW master_index_group_stats (master_index_id, groups, valid_groups, keys, valid_keys) AS
SELECT v.master_index_id, COUNT(*), COUNT(c.id), COUNT(*) FILTER (WHERE c.encrypted), COUNT(k.id)
FROM master_index_valid_indexes v
JOIN index_groups ig ON ig.container_id = v.container_id
LEFT JOIN groups g ON g.archive_id = v.archive_id AND g.group_id = ig.group_id AND (
(g.version = ig.version AND NOT g.version_truncated) OR
(g.version = ig.version & 65535 AND g.version_truncated)
)
LEFT JOIN containers c on c.id = g.container_id AND c.crc32 = ig.crc32
LEFT JOIN keys k ON k.id = c.key_id
GROUP BY v.master_index_id;
CREATE UNIQUE INDEX ON master_index_group_stats (master_index_id);
-- @formatter:on -- @formatter:on

@ -8,6 +8,9 @@
<th>Build</th> <th>Build</th>
<th>Timestamp</th> <th>Timestamp</th>
<th>Name</th> <th>Name</th>
<th>Indexes</th>
<th>Groups</th>
<th>Keys</th>
<th>Download</th> <th>Download</th>
</tr> </tr>
</thead> </thead>
@ -18,6 +21,9 @@
<td th:text="${cache.build}">550</td> <td th:text="${cache.build}">550</td>
<td th:text="${#temporals.formatISO(cache.timestamp)}"></td> <td th:text="${#temporals.formatISO(cache.timestamp)}"></td>
<td th:text="${cache.name}"></td> <td th:text="${cache.name}"></td>
<td th:text="${cache.archiveStats}? ${cache.archiveStats.validIndexes} + ' / ' + ${cache.archiveStats.indexes} : 'Calculating...'">Calculating...</td>
<td th:text="${cache.groupStats}? ${cache.groupStats.validGroups} + ' / ' + ${cache.groupStats.groups} : 'Calculating...'">Calculating...</td>
<td th:text="${cache.groupStats}? ${cache.groupStats.validKeys} + ' / ' + ${cache.groupStats.keys} : 'Calculating...'">Calculating...</td>
<td> <td>
<a th:href="${'/caches/' + cache.id + '.zip'}">Cache</a> <a th:href="${'/caches/' + cache.id + '.zip'}">Cache</a>
<a th:href="${'/caches/' + cache.id + '.json'}">Keys</a> <a th:href="${'/caches/' + cache.id + '.json'}">Keys</a>

Loading…
Cancel
Save