Use advisory locks to prevent concurrent view refreshes

Signed-off-by: Graham <gpe@openrs2.org>
master
Graham 3 years ago
parent 35f54fd753
commit c9f397759e
  1. 15
      archive/src/main/kotlin/org/openrs2/archive/cache/CacheImporter.kt

@ -1330,6 +1330,21 @@ public class CacheImporter @Inject constructor(
public suspend fun refreshViews() { public suspend fun refreshViews() {
database.execute { connection -> database.execute { connection ->
connection.prepareStatement("""
SELECT pg_try_advisory_lock(0)
""".trimIndent()).use { stmt ->
stmt.executeQuery().use { rows ->
if (!rows.next()) {
throw IllegalStateException()
}
val locked = rows.getBoolean(1)
if (!locked) {
return@execute
}
}
}
connection.prepareStatement( connection.prepareStatement(
""" """
REFRESH MATERIALIZED VIEW CONCURRENTLY index_stats REFRESH MATERIALIZED VIEW CONCURRENTLY index_stats

Loading…
Cancel
Save