mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-12 01:07:46 +00:00
Merge pull request #3288 from vitorpamplona/claude/determined-ritchie-g281jh
Fix unstable sort in live activity feeds by snapshotting status order
This commit is contained in:
+8
-1
@@ -106,10 +106,17 @@ open class DiscoverLiveFeedFilter(
|
||||
val allParticipants =
|
||||
items.associate { it to counter.countFollowsThatParticipateOn(it, null) }
|
||||
|
||||
// Snapshots the status order once per item. convertStatusToOrder reads the
|
||||
// OnlineChecker cache and the moving five-minute window, both of which can change
|
||||
// mid-sort (a background online check can update the cache). Reading it lazily inside
|
||||
// the comparator makes the ordering unstable and TimSort throws
|
||||
// "Comparison method violates its general contract!".
|
||||
val statusOrders = items.associateWith { convertStatusToOrder(it.event) }
|
||||
|
||||
return items
|
||||
.sortedWith(
|
||||
compareBy(
|
||||
{ convertStatusToOrder(it.event) },
|
||||
{ statusOrders[it] },
|
||||
{ participantCounts[it] },
|
||||
{ allParticipants[it] },
|
||||
{
|
||||
|
||||
+8
-1
@@ -106,10 +106,17 @@ class LiveStreamsFeedFilter(
|
||||
val allParticipants =
|
||||
items.associate { it to counter.countFollowsThatParticipateOn(it, null) }
|
||||
|
||||
// Snapshots the status order once per item. convertStatusToOrder reads the
|
||||
// OnlineChecker cache and the moving five-minute window, both of which can change
|
||||
// mid-sort (a background online check can update the cache). Reading it lazily inside
|
||||
// the comparator makes the ordering unstable and TimSort throws
|
||||
// "Comparison method violates its general contract!".
|
||||
val statusOrders = items.associateWith { convertStatusToOrder(it.event) }
|
||||
|
||||
return items
|
||||
.sortedWith(
|
||||
compareBy(
|
||||
{ convertStatusToOrder(it.event) },
|
||||
{ statusOrders[it] },
|
||||
{ participantCounts[it] },
|
||||
{ allParticipants[it] },
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user