Keeps the hasher cache on the seed module

This commit is contained in:
Vitor Pamplona
2025-12-24 15:28:59 -05:00
parent f1298c3133
commit 09eeebba94
3 changed files with 7 additions and 6 deletions
@@ -33,13 +33,9 @@ import com.vitorpamplona.quartz.utils.EventFactory
class EventIndexesModule(
val fts: FullTextSearchModule,
val seedModule: SeedModule,
val hasher: (db: SQLiteDatabase) -> TagNameValueHasher,
val tagIndexStrategy: IndexingStrategy = IndexingStrategy(),
) : IModule {
private var hasherCache: TagNameValueHasher? = null
fun hasher(db: SQLiteDatabase): TagNameValueHasher = hasherCache ?: TagNameValueHasher(seedModule.getSeed(db)).also { hasherCache = it }
override fun create(db: SQLiteDatabase) {
db.execSQL(
"""
@@ -44,8 +44,9 @@ class SQLiteEventStore(
}
val seedModule = SeedModule()
val fullTextSearchModule = FullTextSearchModule()
val eventIndexModule = EventIndexesModule(fullTextSearchModule, seedModule, tagIndexStrategy)
val eventIndexModule = EventIndexesModule(fullTextSearchModule, seedModule::hasher, tagIndexStrategy)
val replaceableModule = ReplaceableModule()
val addressableModule = AddressableModule()
@@ -76,4 +76,8 @@ class SeedModule : IModule {
}
override fun deleteAll(db: SQLiteDatabase) {}
private var hasherCache: TagNameValueHasher? = null
fun hasher(db: SQLiteDatabase): TagNameValueHasher = hasherCache ?: TagNameValueHasher(getSeed(db)).also { hasherCache = it }
}