From 068ba3b717759667aaa7eed279d76cd8ee509b46 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Sat, 27 Dec 2025 12:40:23 -0500 Subject: [PATCH] Vacuum and Analyze are blocking, so moving to a coroutine. --- .../nip01Core/store/sqlite/SQLiteEventStore.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/SQLiteEventStore.kt b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/SQLiteEventStore.kt index e947d234f..c6b202262 100644 --- a/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/SQLiteEventStore.kt +++ b/quartz/src/androidMain/kotlin/com/vitorpamplona/quartz/nip01Core/store/sqlite/SQLiteEventStore.kt @@ -32,6 +32,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter import com.vitorpamplona.quartz.nip01Core.store.IEventStore import com.vitorpamplona.quartz.nip01Core.store.sqlite.EventIndexesModule.IndexingStrategy import com.vitorpamplona.quartz.nip40Expiration.isExpired +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class SQLiteEventStore( val context: Context, @@ -113,16 +115,20 @@ class SQLiteEventStore( modules.reversed().forEach { it.deleteAll(db) } } - fun vacuum() { + suspend fun vacuum() { // 1. ANALYZE: Collects statistics about tables and indices // to help the query planner optimize queries. - writableDatabase.execSQL("VACUUM") + withContext(Dispatchers.IO) { + writableDatabase.execSQL("VACUUM") + } } - fun analyse() { + suspend fun analyse() { // 2. VACUUM: Rebuilds the database file, reclaiming unused space // and reducing fragmentation. - writableDatabase.execSQL("ANALYZE") + withContext(Dispatchers.IO) { + writableDatabase.execSQL("ANALYZE") + } } private fun innerInsertEvent(