Caching followingChannels and followingUsers to speed Global filter up

This commit is contained in:
Vitor Pamplona
2023-03-15 13:39:47 -04:00
parent dbc155454f
commit 83a8558f23

View File

@@ -10,20 +10,25 @@ import com.vitorpamplona.amethyst.service.model.TextNoteEvent
object GlobalFeedFilter : FeedFilter<Note>() { object GlobalFeedFilter : FeedFilter<Note>() {
lateinit var account: Account lateinit var account: Account
override fun feed() = LocalCache.notes.values override fun feed(): List<Note> {
.asSequence() val followChannels = account.followingChannels()
.filter { val followUsers = account.followingKeySet()
(it.event is TextNoteEvent || it.event is LongTextNoteEvent || it.event is ChannelMessageEvent) &&
it.replyTo.isNullOrEmpty() return LocalCache.notes.values
} .asSequence()
.filter { .filter {
// does not show events already in the public chat list (it.event is TextNoteEvent || it.event is LongTextNoteEvent || it.event is ChannelMessageEvent) &&
(it.channel() == null || it.channel() !in account.followingChannels()) && it.replyTo.isNullOrEmpty()
// does not show people the user already follows }
(it.author?.pubkeyHex !in account.followingKeySet()) .filter {
} // does not show events already in the public chat list
.filter { account.isAcceptable(it) } (it.channel() == null || it.channel() !in followChannels) &&
.sortedBy { it.createdAt() } // does not show people the user already follows
.toList() (it.author?.pubkeyHex !in followUsers)
.reversed() }
.filter { account.isAcceptable(it) }
.sortedBy { it.createdAt() }
.toList()
.reversed()
}
} }