improves the speed of the kind filter for DVMs

This commit is contained in:
Vitor Pamplona
2024-06-01 15:20:26 -04:00
parent 4faee68174
commit f26fa71e49
2 changed files with 4 additions and 2 deletions
@@ -53,7 +53,7 @@ open class DiscoverNIP89FeedFilter(
val notes = val notes =
LocalCache.addressables.filterIntoSet { _, it -> LocalCache.addressables.filterIntoSet { _, it ->
val noteEvent = it.event val noteEvent = it.event
noteEvent is AppDefinitionEvent && filterParams.match(noteEvent) && noteEvent.supportedKinds().contains(5300) && noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent) noteEvent is AppDefinitionEvent && filterParams.match(noteEvent) && noteEvent.includeKind("5300") && noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent)
} }
return sort(notes) return sort(notes)
@@ -77,7 +77,7 @@ open class DiscoverNIP89FeedFilter(
return collection.filterTo(HashSet()) { return collection.filterTo(HashSet()) {
val noteEvent = it.event val noteEvent = it.event
noteEvent is AppDefinitionEvent && filterParams.match(noteEvent) && noteEvent.supportedKinds().contains(5300) && noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent) noteEvent is AppDefinitionEvent && filterParams.match(noteEvent) && noteEvent.includeKind("5300") && noteEvent.createdAt > TimeUtils.now() - lastAnnounced // && params.match(noteEvent)
} }
} }
@@ -147,6 +147,8 @@ class AppDefinitionEvent(
.filter { it.size > 1 && it[0] == "k" } .filter { it.size > 1 && it[0] == "k" }
.mapNotNull { runCatching { it[1].toInt() }.getOrNull() } .mapNotNull { runCatching { it[1].toInt() }.getOrNull() }
fun includeKind(kind: String) = tags.any { it.size > 1 && it[0] == "k" && it[1] == kind }
fun publishedAt() = tags.firstOrNull { it.size > 1 && it[0] == "published_at" }?.get(1) fun publishedAt() = tags.firstOrNull { it.size > 1 && it[0] == "published_at" }?.get(1)
companion object { companion object {