Better filter for People Lists

This commit is contained in:
Vitor Pamplona
2025-10-29 15:55:33 -04:00
parent 6d8b5fa85d
commit 56a856cf71
3 changed files with 24 additions and 13 deletions

View File

@@ -45,6 +45,28 @@ fun kindEnd(kind: Int) = kindEnd(kind, END_KEY)
val ACCEPT_ALL_FILTER = CacheCollectors.BiFilter<Address, AddressableNote> { key, note -> true } val ACCEPT_ALL_FILTER = CacheCollectors.BiFilter<Address, AddressableNote> { key, note -> true }
fun LargeSoftCache<Address, AddressableNote>.filter(
kind: Int,
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
): List<AddressableNote> = filter(kindStart(kind), kindEnd(kind), consumer)
fun LargeSoftCache<Address, AddressableNote>.filter(
kinds: List<Int>,
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
): List<AddressableNote> {
val set = mutableSetOf<AddressableNote>()
kinds.forEach {
set.addAll(filter(kindStart(it), kindEnd(it), consumer))
}
return set.toList()
}
fun LargeSoftCache<Address, AddressableNote>.filter(
kind: Int,
pubKey: HexKey,
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,
): List<AddressableNote> = filter(kindStart(kind, pubKey), kindEnd(kind, pubKey), consumer)
fun LargeSoftCache<Address, AddressableNote>.filterIntoSet( fun LargeSoftCache<Address, AddressableNote>.filterIntoSet(
kind: Int, kind: Int,
consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER, consumer: CacheCollectors.BiFilter<Address, AddressableNote> = ACCEPT_ALL_FILTER,

View File

@@ -2126,18 +2126,7 @@ object LocalCache : ILocalCache {
} }
} }
fun getFollowSetNotesFor(user: User): List<AddressableNote> { fun getPeopleListNotesFor(user: User): List<AddressableNote> = addressables.filter(PeopleListEvent.KIND, user.pubkeyHex)
checkNotInMainThread()
return addressables
.filter { _, note ->
val listEvent = note.event
(
listEvent is PeopleListEvent &&
user.pubkeyHex == listEvent.pubKey
)
}
}
fun findStatusesForUser(user: User): ImmutableList<AddressableNote> { fun findStatusesForUser(user: User): ImmutableList<AddressableNote> {
checkNotInMainThread() checkNotInMainThread()

View File

@@ -47,7 +47,7 @@ class FollowSetState(
suspend fun getFollowSetNotes() = suspend fun getFollowSetNotes() =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
val followSetNotes = LocalCache.getFollowSetNotesFor(user) val followSetNotes = cache.getPeopleListNotesFor(user)
return@withContext followSetNotes return@withContext followSetNotes
} }