Add estimated cache size column

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 4 years ago
parent ee567cc76f
commit 9be1a54b76
  1. 2
      all/build.gradle.kts
  2. 1
      archive/build.gradle.kts
  3. 20
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheExporter.kt
  4. 11
      archive/src/main/resources/org/openrs2/archive/templates/caches/index.html
  5. 6
      archive/src/main/resources/org/openrs2/archive/templates/caches/show.html
  6. 1
      buildSrc/src/main/kotlin/Versions.kt

@ -27,6 +27,8 @@ tasks.shadowJar {
archiveFileName.set("openrs2.jar") archiveFileName.set("openrs2.jar")
minimize { minimize {
// currently only invoked with reflection in Thymeleaf templates
exclude(dependency("com.jakewharton.byteunits:byteunits"))
exclude(dependency("org.jetbrains.kotlin:kotlin-reflect")) exclude(dependency("org.jetbrains.kotlin:kotlin-reflect"))
} }
} }

@ -23,6 +23,7 @@ dependencies {
implementation(project(":util")) implementation(project(":util"))
implementation(project(":yaml")) implementation(project(":yaml"))
implementation("com.google.guava:guava:${Versions.guava}") implementation("com.google.guava:guava:${Versions.guava}")
implementation("com.jakewharton.byteunits:byteunits:${Versions.byteUnits}")
implementation("com.zaxxer:HikariCP:${Versions.hikaricp}") implementation("com.zaxxer:HikariCP:${Versions.hikaricp}")
implementation("io.ktor:ktor-jackson:${Versions.ktor}") implementation("io.ktor:ktor-jackson:${Versions.ktor}")
implementation("io.ktor:ktor-server-netty:${Versions.ktor}") implementation("io.ktor:ktor-server-netty:${Versions.ktor}")

@ -25,7 +25,8 @@ public class CacheExporter @Inject constructor(
val validGroups: Long, val validGroups: Long,
val groups: Long, val groups: Long,
val validKeys: Long, val validKeys: Long,
val keys: Long val keys: Long,
val size: Long
) { ) {
public val allIndexesValid: Boolean = indexes == validIndexes && indexes != 0L public val allIndexesValid: Boolean = indexes == validIndexes && indexes != 0L
public val validIndexesFraction: Double = if (indexes == 0L) { public val validIndexesFraction: Double = if (indexes == 0L) {
@ -87,12 +88,14 @@ public class CacheExporter @Inject constructor(
ms.valid_groups, ms.valid_groups,
ms.groups, ms.groups,
ms.valid_keys, ms.valid_keys,
ms.keys ms.keys,
ms.size
FROM master_indexes m FROM master_indexes m
JOIN sources s ON s.master_index_id = m.id JOIN sources s ON s.master_index_id = m.id
JOIN games g ON g.id = s.game_id JOIN games g ON g.id = s.game_id
LEFT JOIN master_index_stats ms ON ms.master_index_id = m.id LEFT JOIN master_index_stats ms ON ms.master_index_id = m.id
GROUP BY m.id, g.name, ms.valid_indexes, ms.indexes, ms.valid_groups, ms.groups, ms.valid_keys, ms.keys GROUP BY m.id, g.name, ms.valid_indexes, ms.indexes, ms.valid_groups, ms.groups, ms.valid_keys, ms.keys,
ms.size
ORDER BY g.name ASC, MIN(s.build) ASC, MIN(s.timestamp) ASC ORDER BY g.name ASC, MIN(s.build) ASC, MIN(s.timestamp) ASC
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
@ -113,7 +116,8 @@ public class CacheExporter @Inject constructor(
val groups = rows.getLong(9) val groups = rows.getLong(9)
val validKeys = rows.getLong(10) val validKeys = rows.getLong(10)
val keys = rows.getLong(11) val keys = rows.getLong(11)
Stats(validIndexes, indexes, validGroups, groups, validKeys, keys) val size = rows.getLong(12)
Stats(validIndexes, indexes, validGroups, groups, validKeys, keys, size)
} else { } else {
null null
} }
@ -152,13 +156,14 @@ public class CacheExporter @Inject constructor(
ms.valid_groups, ms.valid_groups,
ms.groups, ms.groups,
ms.valid_keys, ms.valid_keys,
ms.keys ms.keys,
ms.size
FROM master_indexes m FROM master_indexes m
JOIN sources s ON s.master_index_id = m.id JOIN sources s ON s.master_index_id = m.id
JOIN games g ON g.id = s.game_id JOIN games g ON g.id = s.game_id
LEFT JOIN master_index_stats ms ON ms.master_index_id = m.id LEFT JOIN master_index_stats ms ON ms.master_index_id = m.id
WHERE m.id = ? WHERE m.id = ?
GROUP BY m.id, ms.valid_indexes, ms.indexes, ms.valid_groups, ms.groups, ms.valid_keys, ms.keys GROUP BY m.id, ms.valid_indexes, ms.indexes, ms.valid_groups, ms.groups, ms.valid_keys, ms.keys, ms.size
""".trimIndent() """.trimIndent()
).use { stmt -> ).use { stmt ->
stmt.setInt(1, id) stmt.setInt(1, id)
@ -182,7 +187,8 @@ public class CacheExporter @Inject constructor(
val groups = rows.getLong(10) val groups = rows.getLong(10)
val validKeys = rows.getLong(11) val validKeys = rows.getLong(11)
val keys = rows.getLong(12) val keys = rows.getLong(12)
Stats(validIndexes, indexes, validGroups, groups, validKeys, keys) val size = rows.getLong(13)
Stats(validIndexes, indexes, validGroups, groups, validKeys, keys, size)
} else { } else {
null null
} }

@ -22,6 +22,7 @@
<th>Indexes</th> <th>Indexes</th>
<th>Groups</th> <th>Groups</th>
<th>Keys<sup><a href="#empty-locs">1</a></sup></th> <th>Keys<sup><a href="#empty-locs">1</a></sup></th>
<th>Size<sup><a href="#size">2</a></sup></th>
<th>Links</th> <th>Links</th>
</tr> </tr>
</thead> </thead>
@ -65,6 +66,9 @@
<span <span
th:text="${cache.stats}? '(' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')'"></span> th:text="${cache.stats}? '(' + ${#numbers.formatPercent(cache.stats.validKeysFraction, 1, 2)} + ')'"></span>
</td> </td>
<td th:text="${cache.stats}? ${@com.jakewharton.byteunits.BinaryByteUnit@format(cache.stats.size)} : 'Calculating...'"
class="text-right">Calculating...
</td>
<td> <td>
<div class="btn-group"> <div class="btn-group">
<div class="btn-group"> <div class="btn-group">
@ -107,6 +111,13 @@
be used to replace the empty encrypted loc groups with be used to replace the empty encrypted loc groups with
unencrypted replacements. unencrypted replacements.
</p> </p>
<p>
<sup id="size">2</sup> Estimated based on the total compressed
length of all groups in the cache. The native
<code>.dat2</code>/<code>.idx</code> format has some overhead
above this, but the <code>.zip</code> file generated by the
archiving service will reduce the overhead.
</p>
</main> </main>
</body> </body>
</html> </html>

@ -65,6 +65,12 @@
Calculating... Calculating...
</td> </td>
</tr> </tr>
<tr class="thead-dark">
<th>Size<sup><a href="/caches#size">2</a></sup></th>
<td th:text="${cache.stats}? ${@com.jakewharton.byteunits.BinaryByteUnit@format(cache.stats.size)} : 'Calculating...'">
Calculating...
</td>
</tr>
<tr class="thead-dark"> <tr class="thead-dark">
<th>Download</th> <th>Download</th>
<td> <td>

@ -3,6 +3,7 @@ object Versions {
const val bootstrap = "4.6.0-1" const val bootstrap = "4.6.0-1"
const val bouncyCastlePkix = "1.68" const val bouncyCastlePkix = "1.68"
const val bouncyCastleProvider = "1.68" const val bouncyCastleProvider = "1.68"
const val byteUnits = "0.9.1"
const val clikt = "3.1.0" const val clikt = "3.1.0"
const val commonsCompress = "1.20" const val commonsCompress = "1.20"
const val dependencyLicenseReport = "1.16" const val dependencyLicenseReport = "1.16"

Loading…
Cancel
Save