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 0559e8e9df..0611d73145 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt @@ -17,12 +17,17 @@ public class CacheExporter @Inject constructor( private val database: Database, 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( val id: Int, val game: String, val build: Int?, val timestamp: Instant?, - val name: String? + val name: String?, + val archiveStats: ArchiveStats?, + val groupStats: GroupStats? ) public data class Key( @@ -38,10 +43,14 @@ public class CacheExporter @Inject constructor( return database.execute { connection -> 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 JOIN games g ON g.id = m.game_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 """.trimIndent() ).use { stmt -> @@ -60,7 +69,25 @@ public class CacheExporter @Inject constructor( val timestamp = rows.getTimestamp(4)?.toInstant() 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 diff --git a/archive/src/main/resources/org/openrs2/archive/V1__init.sql b/archive/src/main/resources/org/openrs2/archive/V1__init.sql index ae6dfa7754..1477ffcba0 100644 --- a/archive/src/main/resources/org/openrs2/archive/V1__init.sql +++ b/archive/src/main/resources/org/openrs2/archive/V1__init.sql @@ -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) ) 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 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 8575a6392b..2cbdcaafb8 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 @@ -8,6 +8,9 @@