Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicReference

private const val QUERIES_TO_RETRY = 3
private const val SYNC_MAX_CIDS = 100

/**
* This class is responsible to sync messages, reactions and channel data. It tries to sync then, if necessary,
Expand Down Expand Up @@ -303,10 +304,11 @@ internal class SyncManager(
val lastSyncAt = syncState?.lastSyncedAt ?: Date(now())
val rawLastSyncAt = syncState?.rawLastSyncedAt
logger.v { "[performSync] lastSyncAt: $lastSyncAt, rawLastSyncAt: $rawLastSyncAt" }
val cappedCids = cids.take(SYNC_MAX_CIDS)
val result = if (rawLastSyncAt != null) {
chatClient.getSyncHistory(cids, rawLastSyncAt).await()
chatClient.getSyncHistory(cappedCids, rawLastSyncAt).await()
} else {
chatClient.getSyncHistory(cids, lastSyncAt).await()
chatClient.getSyncHistory(cappedCids, lastSyncAt).await()
}
if (result.isTooManyEventsToSyncError()) {
logger.e { "[performSync] failed (too many events to sync): $result" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.times
Expand Down Expand Up @@ -223,6 +224,27 @@ internal class SyncManagerTest {
}
}

@Test
fun `performSync caps channel_cids at 100`() = runTest(testDispatcher) {
/* Given */
_syncState.value = null
whenever(repositoryFacade.selectSyncState(any())) doReturn null
val cids = (1..150).map { "messaging:channel-$it" }
val expectedCids = cids.take(100)

whenever(chatClient.getSyncHistory(any(), any<Date>())) doReturn TestCall(
Result.Success(emptyList()),
)

val syncManager = buildSyncManager()

/* When */
syncManager.performSync(cids = cids)

/* Then */
verify(chatClient).getSyncHistory(eq(expectedCids), any<Date>())
}

@Test
fun `test sync max threshold for messages`() = runTest(testDispatcher) {
/* Given */
Expand Down
Loading