46185c55d1
When a user is following several accounts, they may get a stale feed
caused by the subscription request being rejected by relays (due to max filter item limits).
This commit implements a fix that gets around the issue by
creating several chunked filters for the home feed event and contact
metadata subscriptions.
This is a short to medium-term practical fix, where we get around the
practical limitations imposed by most relays. In the future we should
work on longer-term solutions, which will likely require protocol improvements
Main Test
---------
Procedure:
1. Login with Elsat's npub (Or some account that follows about 2K people)
2. Check the home feed. There should be fresh notes.
REPRO:
Device: iPhone 15 simulator
iOS: 17.4
Damus: 1.9 (3) (0d9954290a)
Results:
- No fresh notes, most recent post is from several hours ago (Feed is stale)
FIX TEST:
Device: iPhone 15 simulator
iOS: 17.4
Damus: This commit
Results:
- Fresh notes appear, most recent post is from a few seconds ago.
Other testing:
--------------
- New automated test passing
- All other automated tests passing
- Tested scrolling down the feed on these conditions:
- Device: iPhone 13 Mini
- iOS: 17.4.1
- Accounts:
- One with about 160 contacts and 10 relays (Daniel D’Aquino)
- One with about 1K+ contacts and 9 relays (Freedom Smuggler)
- One with about 981 contacts and 6 relays (jb55)
- Elsat's account (2K+ accounts and 8 relays)
- Result: None of those were stale
Changelog-Fixed: Fix stale feed issue when follow list is too big
Closes: https://github.com/damus-io/damus/issues/2194
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
27 lines
747 B
Swift
27 lines
747 B
Swift
//
|
||
// Array.swift
|
||
// damus
|
||
//
|
||
// Created by Daniel D’Aquino on 2024-05-10.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
extension Array {
|
||
/// Splits the array into chunks of the specified size.
|
||
/// - Parameter size: The maximum size of each chunk.
|
||
/// - Returns: An array of arrays, where each contained array is a chunk of the original array with up to `size` elements.
|
||
func chunked(into size: Int) -> [[Element]] {
|
||
guard size > 0 else { return [self] }
|
||
return stride(from: 0, to: count, by: size).map {
|
||
Array(self[$0..<Swift.min($0 + size, count)])
|
||
}
|
||
}
|
||
}
|
||
|
||
extension Array where Element: Equatable {
|
||
mutating func removeAll(equalTo item: Element) {
|
||
self.removeAll(where: { $0 == item })
|
||
}
|
||
}
|