Create AppMigration09 to remove the cached well-known config from the SDK (#6026)
This value was most likely was incorrectly cached due to a previous issue in the SDK
This commit is contained in:
committed by
GitHub
parent
23d3066a38
commit
98890f5365
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.migration.impl.migrations
|
||||||
|
|
||||||
|
import dev.zacsweers.metro.AppScope
|
||||||
|
import dev.zacsweers.metro.ContributesIntoSet
|
||||||
|
import dev.zacsweers.metro.Inject
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClientProvider
|
||||||
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
import io.element.android.libraries.sessionstorage.api.SessionStore
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure we clear the well-known cached config, since it could be invalid due to an SDK issue.
|
||||||
|
*/
|
||||||
|
@ContributesIntoSet(AppScope::class)
|
||||||
|
@Inject
|
||||||
|
class AppMigration09(
|
||||||
|
private val sessionStore: SessionStore,
|
||||||
|
private val matrixClientProvider: MatrixClientProvider,
|
||||||
|
) : AppMigration {
|
||||||
|
override val order: Int = 9
|
||||||
|
|
||||||
|
override suspend fun migrate(isFreshInstall: Boolean) {
|
||||||
|
if (isFreshInstall) return
|
||||||
|
|
||||||
|
val sessions = sessionStore.getAllSessions()
|
||||||
|
|
||||||
|
for (session in sessions) {
|
||||||
|
val client = matrixClientProvider.getOrRestore(SessionId(session.userId)).getOrNull() ?: continue
|
||||||
|
client.resetWellKnownConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026 Element Creations Ltd.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||||
|
* Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.element.android.features.migration.impl.migrations
|
||||||
|
|
||||||
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
import io.element.android.libraries.matrix.api.core.SessionId
|
||||||
|
import io.element.android.libraries.matrix.test.FakeMatrixClient
|
||||||
|
import io.element.android.libraries.matrix.test.FakeMatrixClientProvider
|
||||||
|
import io.element.android.libraries.sessionstorage.test.InMemorySessionStore
|
||||||
|
import io.element.android.libraries.sessionstorage.test.aSessionData
|
||||||
|
import io.element.android.tests.testutils.lambda.lambdaRecorder
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
class AppMigration09Test {
|
||||||
|
@Test
|
||||||
|
fun `migration on fresh install does nothing`() = runTest {
|
||||||
|
val sessionStore = InMemorySessionStore(initialList = listOf(aSessionData()))
|
||||||
|
val getClientLambda = lambdaRecorder<SessionId, Result<MatrixClient>> { Result.success(FakeMatrixClient()) }
|
||||||
|
val clientProvider = FakeMatrixClientProvider(getClient = getClientLambda)
|
||||||
|
val migration = AppMigration09(sessionStore, clientProvider)
|
||||||
|
migration.migrate(isFreshInstall = true)
|
||||||
|
|
||||||
|
getClientLambda.assertions().isNeverCalled()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `migration on upgrade should invoke the resetWellKnownConfig method`() = runTest {
|
||||||
|
val sessionStore = InMemorySessionStore(initialList = listOf(aSessionData()))
|
||||||
|
val resetWellKnownLambda = lambdaRecorder<Result<Unit>> { Result.success(Unit) }
|
||||||
|
val getClientLambda = lambdaRecorder<SessionId, Result<MatrixClient>> {
|
||||||
|
Result.success(FakeMatrixClient(resetWellKnownConfigLambda = resetWellKnownLambda))
|
||||||
|
}
|
||||||
|
val clientProvider = FakeMatrixClientProvider(getClient = getClientLambda)
|
||||||
|
val migration = AppMigration09(sessionStore, clientProvider)
|
||||||
|
migration.migrate(isFreshInstall = false)
|
||||||
|
|
||||||
|
getClientLambda.assertions().isCalledOnce()
|
||||||
|
resetWellKnownLambda.assertions().isCalledOnce()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -214,7 +214,15 @@ interface MatrixClient {
|
|||||||
*/
|
*/
|
||||||
fun createLinkDesktopHandler(): Result<LinkDesktopHandler>
|
fun createLinkDesktopHandler(): Result<LinkDesktopHandler>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a database optimization that should flush cached data and improve performance.
|
||||||
|
*/
|
||||||
suspend fun performDatabaseVacuum(): Result<Unit>
|
suspend fun performDatabaseVacuum(): Result<Unit>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resets the cached client `well-known` config by the SDK.
|
||||||
|
*/
|
||||||
|
suspend fun resetWellKnownConfig(): Result<Unit>
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -791,6 +791,13 @@ class RustMatrixClient(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun resetWellKnownConfig(): Result<Unit> {
|
||||||
|
return runCatchingExceptions {
|
||||||
|
Timber.d("Resetting well-known config for session $sessionId")
|
||||||
|
innerClient.resetWellKnown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun getCacheSize(
|
private suspend fun getCacheSize(
|
||||||
includeCryptoDb: Boolean = false,
|
includeCryptoDb: Boolean = false,
|
||||||
): Long = withContext(sessionDispatcher) {
|
): Long = withContext(sessionDispatcher) {
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class FakeMatrixClient(
|
|||||||
private val markRoomAsFullyReadResult: (RoomId, EventId) -> Result<Unit> = { _, _ -> lambdaError() },
|
private val markRoomAsFullyReadResult: (RoomId, EventId) -> Result<Unit> = { _, _ -> lambdaError() },
|
||||||
private val performDatabaseVacuumLambda: () -> Result<Unit> = { lambdaError() },
|
private val performDatabaseVacuumLambda: () -> Result<Unit> = { lambdaError() },
|
||||||
private val getDatabaseSizesLambda: () -> Result<SdkStoreSizes> = { lambdaError() },
|
private val getDatabaseSizesLambda: () -> Result<SdkStoreSizes> = { lambdaError() },
|
||||||
|
private val resetWellKnownConfigLambda: () -> Result<Unit> = { lambdaError() },
|
||||||
) : MatrixClient {
|
) : MatrixClient {
|
||||||
var setDisplayNameCalled: Boolean = false
|
var setDisplayNameCalled: Boolean = false
|
||||||
private set
|
private set
|
||||||
@@ -379,4 +380,8 @@ class FakeMatrixClient(
|
|||||||
override fun createLinkMobileHandler(): Result<LinkMobileHandler> {
|
override fun createLinkMobileHandler(): Result<LinkMobileHandler> {
|
||||||
return createLinkMobileHandlerResult()
|
return createLinkMobileHandlerResult()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun resetWellKnownConfig(): Result<Unit> {
|
||||||
|
return resetWellKnownConfigLambda()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user