From a5da4ea53d684db64babaefbcb98d199532d633d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 7 Apr 2023 14:26:23 -0400 Subject: [PATCH] Streamlines Global filter for performance --- .../amethyst/ui/dal/GlobalFeedFilter.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/GlobalFeedFilter.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/GlobalFeedFilter.kt index f44b43bb4..e902c2f98 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/GlobalFeedFilter.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/dal/GlobalFeedFilter.kt @@ -3,10 +3,7 @@ package com.vitorpamplona.amethyst.ui.dal import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.Note -import com.vitorpamplona.amethyst.service.model.ChannelMessageEvent -import com.vitorpamplona.amethyst.service.model.LongTextNoteEvent -import com.vitorpamplona.amethyst.service.model.PollNoteEvent -import com.vitorpamplona.amethyst.service.model.TextNoteEvent +import com.vitorpamplona.amethyst.service.model.* object GlobalFeedFilter : FeedFilter() { lateinit var account: Account @@ -14,41 +11,43 @@ object GlobalFeedFilter : FeedFilter() { override fun feed(): List { val followChannels = account.followingChannels() val followUsers = account.followingKeySet() + val now = System.currentTimeMillis() / 1000 val notes = LocalCache.notes.values .asSequence() .filter { - (it.event is TextNoteEvent || it.event is LongTextNoteEvent || it.event is PollNoteEvent || it.event is ChannelMessageEvent) && - it.replyTo.isNullOrEmpty() + it.event is BaseTextNoteEvent && it.replyTo.isNullOrEmpty() } .filter { + val channel = it.channel() // 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 (it.author?.pubkeyHex !in followUsers) } .filter { account.isAcceptable(it) } .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. - it.createdAt()!! <= System.currentTimeMillis() / 1000 + it.createdAt()!! <= now } .toList() val longFormNotes = LocalCache.addressables.values .asSequence() .filter { - (it.event is LongTextNoteEvent) && it.replyTo.isNullOrEmpty() + it.event is LongTextNoteEvent && it.replyTo.isNullOrEmpty() } .filter { + val channel = it.channel() // 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 (it.author?.pubkeyHex !in followUsers) } .filter { account.isAcceptable(it) } .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. - it.createdAt()!! <= System.currentTimeMillis() / 1000 + it.createdAt()!! <= now } .toList()