Creating a IndexingStrategy interface
This commit is contained in:
+1
-11
@@ -35,7 +35,7 @@ import com.vitorpamplona.quartz.utils.EventFactory
|
|||||||
class EventIndexesModule(
|
class EventIndexesModule(
|
||||||
val fts: FullTextSearchModule,
|
val fts: FullTextSearchModule,
|
||||||
val hasher: (db: SQLiteDatabase) -> TagNameValueHasher,
|
val hasher: (db: SQLiteDatabase) -> TagNameValueHasher,
|
||||||
val tagIndexStrategy: IndexingStrategy = IndexingStrategy(),
|
val tagIndexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
||||||
) : IModule {
|
) : IModule {
|
||||||
override fun create(db: SQLiteDatabase) {
|
override fun create(db: SQLiteDatabase) {
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
@@ -182,16 +182,6 @@ class EventIndexesModule(
|
|||||||
return headerId
|
return headerId
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* By default, we index all tags that have a single letter name and some value
|
|
||||||
*/
|
|
||||||
class IndexingStrategy {
|
|
||||||
fun shouldIndex(
|
|
||||||
kind: Int,
|
|
||||||
tag: Tag,
|
|
||||||
) = tag.size >= 2 && tag[0].length == 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fun planQuery(
|
fun planQuery(
|
||||||
filter: Filter,
|
filter: Filter,
|
||||||
hasher: TagNameValueHasher,
|
hasher: TagNameValueHasher,
|
||||||
|
|||||||
+1
-2
@@ -24,13 +24,12 @@ import android.content.Context
|
|||||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||||
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
||||||
import com.vitorpamplona.quartz.nip01Core.store.sqlite.EventIndexesModule.IndexingStrategy
|
|
||||||
|
|
||||||
class EventStore(
|
class EventStore(
|
||||||
context: Context,
|
context: Context,
|
||||||
dbName: String? = "events.db",
|
dbName: String? = "events.db",
|
||||||
val relayUrl: String? = "wss://quartz.local",
|
val relayUrl: String? = "wss://quartz.local",
|
||||||
val tagIndexStrategy: IndexingStrategy = IndexingStrategy(),
|
val tagIndexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
||||||
) : IEventStore {
|
) : IEventStore {
|
||||||
val store = SQLiteEventStore(context, dbName, relayUrl, tagIndexStrategy)
|
val store = SQLiteEventStore(context, dbName, relayUrl, tagIndexStrategy)
|
||||||
|
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2025 Vitor Pamplona
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to use,
|
||||||
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||||
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.vitorpamplona.quartz.nip01Core.store.sqlite
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.core.Tag
|
||||||
|
|
||||||
|
interface IndexingStrategy {
|
||||||
|
fun shouldIndex(
|
||||||
|
kind: Int,
|
||||||
|
tag: Tag,
|
||||||
|
): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, we index all tags that have a single letter name and some value
|
||||||
|
*/
|
||||||
|
class DefaultIndexingStrategy : IndexingStrategy {
|
||||||
|
override fun shouldIndex(
|
||||||
|
kind: Int,
|
||||||
|
tag: Tag,
|
||||||
|
) = tag.size >= 2 && tag[0].length == 1
|
||||||
|
}
|
||||||
+1
-2
@@ -30,7 +30,6 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
|||||||
import com.vitorpamplona.quartz.nip01Core.core.isEphemeral
|
import com.vitorpamplona.quartz.nip01Core.core.isEphemeral
|
||||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||||
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
import com.vitorpamplona.quartz.nip01Core.store.IEventStore
|
||||||
import com.vitorpamplona.quartz.nip01Core.store.sqlite.EventIndexesModule.IndexingStrategy
|
|
||||||
import com.vitorpamplona.quartz.nip40Expiration.isExpired
|
import com.vitorpamplona.quartz.nip40Expiration.isExpired
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -39,7 +38,7 @@ class SQLiteEventStore(
|
|||||||
val context: Context,
|
val context: Context,
|
||||||
val dbName: String? = "events.db",
|
val dbName: String? = "events.db",
|
||||||
val relayUrl: String? = null,
|
val relayUrl: String? = null,
|
||||||
val tagIndexStrategy: IndexingStrategy = IndexingStrategy(),
|
val tagIndexStrategy: IndexingStrategy = DefaultIndexingStrategy(),
|
||||||
) : SQLiteOpenHelper(context, dbName, null, DATABASE_VERSION) {
|
) : SQLiteOpenHelper(context, dbName, null, DATABASE_VERSION) {
|
||||||
companion object {
|
companion object {
|
||||||
const val DATABASE_VERSION = 2
|
const val DATABASE_VERSION = 2
|
||||||
|
|||||||
Reference in New Issue
Block a user