mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 04:52:31 +02:00
Streamlines Global filter for performance
This commit is contained in:
@@ -3,10 +3,7 @@ package com.vitorpamplona.amethyst.ui.dal
|
|||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent
|
import com.vitorpamplona.amethyst.service.model.*
|
||||||
import com.vitorpamplona.amethyst.service.model.LongTextNoteEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.PollNoteEvent
|
|
||||||
import com.vitorpamplona.amethyst.service.model.TextNoteEvent
|
|
||||||
|
|
||||||
object GlobalFeedFilter : FeedFilter<Note>() {
|
object GlobalFeedFilter : FeedFilter<Note>() {
|
||||||
lateinit var account: Account
|
lateinit var account: Account
|
||||||
@@ -14,41 +11,43 @@ object GlobalFeedFilter : FeedFilter<Note>() {
|
|||||||
override fun feed(): List<Note> {
|
override fun feed(): List<Note> {
|
||||||
val followChannels = account.followingChannels()
|
val followChannels = account.followingChannels()
|
||||||
val followUsers = account.followingKeySet()
|
val followUsers = account.followingKeySet()
|
||||||
|
val now = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
val notes = LocalCache.notes.values
|
val notes = LocalCache.notes.values
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
(it.event is TextNoteEvent || it.event is LongTextNoteEvent || it.event is PollNoteEvent || it.event is ChannelMessageEvent) &&
|
it.event is BaseTextNoteEvent && it.replyTo.isNullOrEmpty()
|
||||||
it.replyTo.isNullOrEmpty()
|
|
||||||
}
|
}
|
||||||
.filter {
|
.filter {
|
||||||
|
val channel = it.channel()
|
||||||
// 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 followChannels) &&
|
(channel == null || channel !in followChannels) &&
|
||||||
// does not show people the user already follows
|
// does not show people the user already follows
|
||||||
(it.author?.pubkeyHex !in followUsers)
|
(it.author?.pubkeyHex !in followUsers)
|
||||||
}
|
}
|
||||||
.filter { account.isAcceptable(it) }
|
.filter { account.isAcceptable(it) }
|
||||||
.filter {
|
.filter {
|
||||||
// Do not show notes with the creation time exceeding the current time, as they will always stay at the top of the global feed, which is cheating.
|
// Do not show notes with the creation time exceeding the current time, as they will always stay at the top of the global feed, which is cheating.
|
||||||
it.createdAt()!! <= System.currentTimeMillis() / 1000
|
it.createdAt()!! <= now
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
val longFormNotes = LocalCache.addressables.values
|
val longFormNotes = LocalCache.addressables.values
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.filter {
|
.filter {
|
||||||
(it.event is LongTextNoteEvent) && it.replyTo.isNullOrEmpty()
|
it.event is LongTextNoteEvent && it.replyTo.isNullOrEmpty()
|
||||||
}
|
}
|
||||||
.filter {
|
.filter {
|
||||||
|
val channel = it.channel()
|
||||||
// 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 followChannels) &&
|
(channel == null || channel !in followChannels) &&
|
||||||
// does not show people the user already follows
|
// does not show people the user already follows
|
||||||
(it.author?.pubkeyHex !in followUsers)
|
(it.author?.pubkeyHex !in followUsers)
|
||||||
}
|
}
|
||||||
.filter { account.isAcceptable(it) }
|
.filter { account.isAcceptable(it) }
|
||||||
.filter {
|
.filter {
|
||||||
// Do not show notes with the creation time exceeding the current time, as they will always stay at the top of the global feed, which is cheating.
|
// Do not show notes with the creation time exceeding the current time, as they will always stay at the top of the global feed, which is cheating.
|
||||||
it.createdAt()!! <= System.currentTimeMillis() / 1000
|
it.createdAt()!! <= now
|
||||||
}
|
}
|
||||||
.toList()
|
.toList()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user