mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-22 18:13:13 +02:00
Caching followingChannels and followingUsers to speed Global filter up
This commit is contained in:
@@ -10,7 +10,11 @@ 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> {
|
||||||
|
val followChannels = account.followingChannels()
|
||||||
|
val followUsers = account.followingKeySet()
|
||||||
|
|
||||||
|
return LocalCache.notes.values
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
(it.event is TextNoteEvent || it.event is LongTextNoteEvent || it.event is ChannelMessageEvent) &&
|
(it.event is TextNoteEvent || it.event is LongTextNoteEvent || it.event is ChannelMessageEvent) &&
|
||||||
@@ -18,12 +22,13 @@ object GlobalFeedFilter : FeedFilter<Note>() {
|
|||||||
}
|
}
|
||||||
.filter {
|
.filter {
|
||||||
// does not show events already in the public chat list
|
// does not show events already in the public chat list
|
||||||
(it.channel() == null || it.channel() !in account.followingChannels()) &&
|
(it.channel() == null || it.channel() !in followChannels) &&
|
||||||
// does not show people the user already follows
|
// does not show people the user already follows
|
||||||
(it.author?.pubkeyHex !in account.followingKeySet())
|
(it.author?.pubkeyHex !in followUsers)
|
||||||
}
|
}
|
||||||
.filter { account.isAcceptable(it) }
|
.filter { account.isAcceptable(it) }
|
||||||
.sortedBy { it.createdAt() }
|
.sortedBy { it.createdAt() }
|
||||||
.toList()
|
.toList()
|
||||||
.reversed()
|
.reversed()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user