Skip to content

Commit d8f0e2f

Browse files
authored
Limit synced channels count to 100 (#3863)
1 parent f40b983 commit d8f0e2f

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
- Fix `ChannelController.hasLoadedAllPreviousMessages` not correct for newly created channels [#3855](https://github.com/GetStream/stream-chat-swift/pull/3855)
99
- Fix duplicated watch channel requests when a channel is created and it belongs to multiple queries [#3857](https://github.com/GetStream/stream-chat-swift/pull/3857)
1010
- Fix calling watch channel request when a channel is updated and it already belongs to another query [#3857](https://github.com/GetStream/stream-chat-swift/pull/3857)
11+
- Fix syncing error when trying to sync too many channels [#3863](https://github.com/GetStream/stream-chat-swift/pull/3863)
1112

1213
## StreamChatUI
1314
### 🐞 Fixed

Sources/StreamChat/Repositories/SyncOperations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ final class SyncEventsOperation: AsyncOperation, @unchecked Sendable {
122122
}
123123

124124
syncRepository?.syncChannelsEvents(
125-
channelIds: Array(channelIds),
125+
channelIds: Array(channelIds.prefix(100)),
126126
lastSyncAt: context.lastSyncAt,
127127
isRecovery: recovery
128128
) { result in

TestTools/StreamChatTestTools/Mocks/StreamChat/Repositories/SyncRepository_Mock.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ final class SyncRepository_Mock: SyncRepository, Spy {
1212

1313
let spyState = SpyState()
1414
var syncMissingEventsResult: Result<[ChannelId], SyncError>?
15+
var syncMissingEvents_syncChannels: [ChannelId]?
1516

1617
convenience init() {
1718
let apiClient = APIClient_Spy()
@@ -59,6 +60,7 @@ final class SyncRepository_Mock: SyncRepository, Spy {
5960
completion: @escaping (Result<[ChannelId], SyncError>) -> Void
6061
) {
6162
record()
63+
syncMissingEvents_syncChannels = channelIds
6264
syncMissingEventsResult.map(completion)
6365
}
6466
}

Tests/StreamChatTests/Repositories/SyncOperations_Tests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ final class SyncOperations_Tests: XCTestCase {
6969
times: 1
7070
)
7171
}
72+
73+
func test_SyncEventsOperation_limitChannelIdsTo100() throws {
74+
let context = SyncContext(lastSyncAt: .init())
75+
context.localChannelIds = Set((0..<255).map { ChannelId(type: .messaging, id: "\($0)") })
76+
try database.createCurrentUser()
77+
try database.writeSynchronously { session in
78+
session.currentUser?.lastSynchedEventDate = DBDate().addingTimeInterval(-3600)
79+
}
80+
81+
let operation = SyncEventsOperation(syncRepository: syncRepository, context: context, recovery: false)
82+
syncRepository.syncMissingEventsResult = .success([.unique])
83+
84+
operation.startAndWaitForCompletion()
85+
86+
XCTAssertEqual(syncRepository.syncMissingEvents_syncChannels?.count, 100)
87+
XCTAssertCall(
88+
"syncChannelsEvents(channelIds:lastSyncAt:isRecovery:completion:)",
89+
on: syncRepository,
90+
times: 1
91+
)
92+
}
7293

7394
// MARK: - WatchChannelOperation
7495

0 commit comments

Comments
 (0)