Merge pull request #8461 from vector-im/feature/bca/fix_several_anr

Fix several app non responsive issues
This commit is contained in:
Valere 2023-05-23 18:32:13 +02:00 committed by GitHub
commit 591b08f1ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 28 deletions

1
changelog.d/8454.bugfix Normal file
View File

@ -0,0 +1 @@
Fix several performance issues causing app non responsive issues.

View File

@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.session.room.read
import com.zhuinden.monarchy.Monarchy
import io.realm.Realm
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.MatrixCoroutineDispatchers
import org.matrix.android.sdk.api.session.events.model.LocalEcho
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
@ -64,9 +66,10 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
private val globalErrorReceiver: GlobalErrorReceiver,
private val clock: Clock,
private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
private val coroutineDispatchers: MatrixCoroutineDispatchers,
) : SetReadMarkersTask {
override suspend fun execute(params: SetReadMarkersTask.Params) {
override suspend fun execute(params: SetReadMarkersTask.Params) = withContext(coroutineDispatchers.io) {
val markers = mutableMapOf<String, String>()
Timber.v("Execute set read marker with params: $params")
val latestSyncedEventId = latestSyncedEventId(params.roomId)

View File

@ -17,6 +17,7 @@
package im.vector.app.core.session.clientinfo
import im.vector.app.core.di.ActiveSessionHolder
import kotlinx.coroutines.withContext
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
import javax.inject.Inject
@ -27,16 +28,19 @@ class DeleteUnusedClientInformationUseCase @Inject constructor(
suspend fun execute(deviceInfoList: List<DeviceInfo>): Result<Unit> = runCatching {
// A defensive approach against local storage reports an empty device list (although it is not a seen situation).
if (deviceInfoList.isEmpty()) return Result.success(Unit)
val expectedClientInfoKeyList = deviceInfoList.map { MATRIX_CLIENT_INFO_KEY_PREFIX + it.deviceId }
activeSessionHolder
.getSafeActiveSession()
?.accountDataService()
?.getUserAccountDataEventsStartWith(MATRIX_CLIENT_INFO_KEY_PREFIX)
?.map { it.type }
?.subtract(expectedClientInfoKeyList.toSet())
?.forEach { userAccountDataKeyToDelete ->
activeSessionHolder.getSafeActiveSession()?.accountDataService()?.deleteUserAccountData(userAccountDataKeyToDelete)
}
val dispatcher = activeSessionHolder.getSafeActiveSession()?.coroutineDispatchers?.io
?: return@runCatching
withContext(dispatcher) {
val expectedClientInfoKeyList = deviceInfoList.map { MATRIX_CLIENT_INFO_KEY_PREFIX + it.deviceId }
activeSessionHolder
.getSafeActiveSession()
?.accountDataService()
?.getUserAccountDataEventsStartWith(MATRIX_CLIENT_INFO_KEY_PREFIX)
?.map { it.type }
?.subtract(expectedClientInfoKeyList.toSet())
?.forEach { userAccountDataKeyToDelete ->
activeSessionHolder.getSafeActiveSession()?.accountDataService()?.deleteUserAccountData(userAccountDataKeyToDelete)
}
}
}
}

View File

@ -322,11 +322,10 @@ class RoomListViewModel @AssistedInject constructor(
}
private fun handleDeleteLocalRooms() {
val localRoomIds = session.roomService()
.getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) })
.map { it.roomId }
viewModelScope.launch {
viewModelScope.launch(session.coroutineDispatchers.io) {
val localRoomIds = session.roomService()
.getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) })
.map { it.roomId }
localRoomIds.forEach {
session.roomService().deleteLocalRoom(it)
}

View File

@ -24,7 +24,9 @@ import im.vector.app.R
import im.vector.app.core.resources.BuildMeta
import im.vector.app.core.utils.FirstThrottler
import im.vector.app.features.displayname.getBestName
import im.vector.app.features.session.coroutineScope
import im.vector.app.features.settings.VectorPreferences
import kotlinx.coroutines.launch
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
import org.matrix.android.sdk.api.session.getUserOrDefault
@ -121,11 +123,15 @@ class NotificationDrawerManager @Inject constructor(
* Used to ignore events related to that room (no need to display notification) and clean any existing notification on this room.
*/
fun setCurrentRoom(roomId: String?) {
updateEvents {
val hasChanged = roomId != currentRoomId
currentRoomId = roomId
if (hasChanged && roomId != null) {
it.clearMessagesForRoom(roomId)
val dispatcher = currentSession?.coroutineDispatchers?.io ?: return
val scope = currentSession?.coroutineScope ?: return
scope.launch(dispatcher) {
updateEvents {
val hasChanged = roomId != currentRoomId
currentRoomId = roomId
if (hasChanged && roomId != null) {
it.clearMessagesForRoom(roomId)
}
}
}
}
@ -135,12 +141,16 @@ class NotificationDrawerManager @Inject constructor(
* Used to ignore events related to that thread (no need to display notification) and clean any existing notification on this room.
*/
fun setCurrentThread(threadId: String?) {
updateEvents {
val hasChanged = threadId != currentThreadId
currentThreadId = threadId
currentRoomId?.let { roomId ->
if (hasChanged && threadId != null) {
it.clearMessagesForThread(roomId, threadId)
val dispatcher = currentSession?.coroutineDispatchers?.io ?: return
val scope = currentSession?.coroutineScope ?: return
scope.launch(dispatcher) {
updateEvents {
val hasChanged = threadId != currentThreadId
currentThreadId = threadId
currentRoomId?.let { roomId ->
if (hasChanged && threadId != null) {
it.clearMessagesForThread(roomId, threadId)
}
}
}
}