From 23bb1ef13c1b13cfad2538b5cbee322fa71394ac Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 23 Feb 2021 22:33:53 +0000 Subject: [PATCH] Add refresh-views command Signed-off-by: Graham --- .../org/openrs2/archive/cache/CacheCommand.kt | 3 ++- .../org/openrs2/archive/cache/CacheImporter.kt | 12 ++++++++++++ .../openrs2/archive/cache/RefreshViewsCommand.kt | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 archive/src/main/kotlin/org/openrs2/archive/cache/RefreshViewsCommand.kt diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheCommand.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheCommand.kt index 2db20266..7786e419 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheCommand.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheCommand.kt @@ -9,7 +9,8 @@ public class CacheCommand : NoOpCliktCommand(name = "cache") { DownloadCommand(), ImportCommand(), ImportMasterIndexCommand(), - ExportCommand() + ExportCommand(), + RefreshViewsCommand() ) } } diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt index 6ae3ba5b..f28c6ba5 100644 --- a/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt @@ -824,6 +824,18 @@ public class CacheImporter @Inject constructor( } } + public suspend fun refreshViews() { + database.execute { connection -> + connection.prepareStatement( + """ + REFRESH MATERIALIZED VIEW CONCURRENTLY master_index_stats + """.trimIndent() + ).use { stmt -> + stmt.execute() + } + } + } + public companion object { private val logger = InlineLogger() diff --git a/archive/src/main/kotlin/org/openrs2/archive/cache/RefreshViewsCommand.kt b/archive/src/main/kotlin/org/openrs2/archive/cache/RefreshViewsCommand.kt new file mode 100644 index 00000000..3bd4bbcf --- /dev/null +++ b/archive/src/main/kotlin/org/openrs2/archive/cache/RefreshViewsCommand.kt @@ -0,0 +1,16 @@ +package org.openrs2.archive.cache + +import com.github.ajalt.clikt.core.CliktCommand +import com.google.inject.Guice +import kotlinx.coroutines.runBlocking +import org.openrs2.archive.ArchiveModule +import org.openrs2.inject.CloseableInjector + +public class RefreshViewsCommand : CliktCommand(name = "refresh-views") { + override fun run(): Unit = runBlocking { + CloseableInjector(Guice.createInjector(ArchiveModule)).use { injector -> + val importer = injector.getInstance(CacheImporter::class.java) + importer.refreshViews() + } + } +}