mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Schedule the background search backfill off the main thread
Checking if the work is already scheduled does a blocking WorkManager query, which was done on the main thread at session start. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+3
@@ -118,6 +118,7 @@ import kotlinx.coroutines.flow.StateFlow
|
|||||||
import kotlinx.coroutines.flow.buffer
|
import kotlinx.coroutines.flow.buffer
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.mapNotNull
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
@@ -1034,6 +1035,8 @@ class RustMatrixClient(
|
|||||||
searchBackfillService.cancelPeriodicSearchBackfill()
|
searchBackfillService.cancelPeriodicSearchBackfill()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Checking the pending work is a blocking call, do not do it on the main thread
|
||||||
|
.flowOn(sessionDispatcher)
|
||||||
.launchIn(sessionCoroutineScope)
|
.launchIn(sessionCoroutineScope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -33,7 +33,9 @@ import io.element.android.services.analytics.test.FakeAnalyticsService
|
|||||||
import io.element.android.services.toolbox.test.systemclock.FakeSystemClock
|
import io.element.android.services.toolbox.test.systemclock.FakeSystemClock
|
||||||
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||||
import io.element.android.tests.testutils.testCoroutineDispatchers
|
import io.element.android.tests.testutils.testCoroutineDispatchers
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.TestScope
|
import kotlinx.coroutines.test.TestScope
|
||||||
|
import kotlinx.coroutines.test.runCurrent
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.rustcomponents.sdk.Client
|
import org.matrix.rustcomponents.sdk.Client
|
||||||
@@ -41,6 +43,7 @@ import org.matrix.rustcomponents.sdk.ClientDelegate
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
|
import org.matrix.rustcomponents.sdk.SyncService as ClientSyncService
|
||||||
|
|
||||||
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
class RustMatrixClientFactoryTest {
|
class RustMatrixClientFactoryTest {
|
||||||
@Test
|
@Test
|
||||||
fun test() = runTest {
|
fun test() = runTest {
|
||||||
@@ -51,6 +54,7 @@ class RustMatrixClientFactoryTest {
|
|||||||
val result = sut.create(aSessionData())
|
val result = sut.create(aSessionData())
|
||||||
|
|
||||||
assertThat(result.sessionId).isEqualTo(SessionId("@alice:server.org"))
|
assertThat(result.sessionId).isEqualTo(SessionId("@alice:server.org"))
|
||||||
|
runCurrent()
|
||||||
// 2 workers are scheduled: one for the search backfill and one for the vacuum
|
// 2 workers are scheduled: one for the search backfill and one for the vacuum
|
||||||
scheduleWorkersLambda.assertions().isCalledExactly(2)
|
scheduleWorkersLambda.assertions().isCalledExactly(2)
|
||||||
result.destroy()
|
result.destroy()
|
||||||
|
|||||||
Reference in New Issue
Block a user