Caches participant counting process to speed sorting up

This commit is contained in:
Vitor Pamplona 2023-07-08 15:37:05 -04:00
parent cfbc4536c6
commit 3fc247d85c
3 changed files with 13 additions and 3 deletions

View File

@ -54,10 +54,13 @@ open class DiscoverChatFeedFilter(val account: Account) : AdditiveFeedFilter<Not
val followingKeySet = account.selectedUsersFollowList(account.defaultDiscoveryFollowList)
val counter = ParticipantListBuilder()
val participantCounts = collection.associate {
it to counter.countFollowsThatParticipateOn(it, followingKeySet)
}
return collection.sortedWith(
compareBy(
{ counter.countFollowsThatParticipateOn(it, followingKeySet) },
{ participantCounts[it] },
{ it.createdAt() },
{ it.idHex }
)

View File

@ -44,11 +44,15 @@ open class DiscoverCommunityFeedFilter(val account: Account) : AdditiveFeedFilte
override fun sort(collection: Set<Note>): List<Note> {
val followingKeySet = account.selectedUsersFollowList(account.defaultDiscoveryFollowList)
val counter = ParticipantListBuilder()
val participantCounts = collection.associate {
it to counter.countFollowsThatParticipateOn(it, followingKeySet)
}
return collection.sortedWith(
compareBy(
{ counter.countFollowsThatParticipateOn(it, followingKeySet) },
{ participantCounts[it] },
{ it.createdAt() },
{ it.idHex }
)

View File

@ -57,11 +57,14 @@ open class DiscoverLiveFeedFilter(val account: Account) : AdditiveFeedFilter<Not
val followingKeySet = account.selectedUsersFollowList(account.defaultDiscoveryFollowList)
val counter = ParticipantListBuilder()
val participantCounts = collection.associate {
it to counter.countFollowsThatParticipateOn(it, followingKeySet)
}
return collection.sortedWith(
compareBy(
{ convertStatusToOrder((it.event as? LiveActivitiesEvent)?.status()) },
{ counter.countFollowsThatParticipateOn(it, followingKeySet) },
{ participantCounts[it] },
{ (it.event as? LiveActivitiesEvent)?.starts() ?: it.createdAt() },
{ it.idHex }
)