mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-15 01:35:07 +08:00
Merge pull request #8461 from vector-im/feature/bca/fix_several_anr
Fix several app non responsive issues
This commit is contained in:
commit
591b08f1ff
1
changelog.d/8454.bugfix
Normal file
1
changelog.d/8454.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix several performance issues causing app non responsive issues.
|
@ -18,6 +18,8 @@ package org.matrix.android.sdk.internal.session.room.read
|
|||||||
|
|
||||||
import com.zhuinden.monarchy.Monarchy
|
import com.zhuinden.monarchy.Monarchy
|
||||||
import io.realm.Realm
|
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.events.model.LocalEcho
|
||||||
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilitiesService
|
||||||
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntity
|
||||||
@ -64,9 +66,10 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
|
|||||||
private val globalErrorReceiver: GlobalErrorReceiver,
|
private val globalErrorReceiver: GlobalErrorReceiver,
|
||||||
private val clock: Clock,
|
private val clock: Clock,
|
||||||
private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
|
private val homeServerCapabilitiesService: HomeServerCapabilitiesService,
|
||||||
|
private val coroutineDispatchers: MatrixCoroutineDispatchers,
|
||||||
) : SetReadMarkersTask {
|
) : SetReadMarkersTask {
|
||||||
|
|
||||||
override suspend fun execute(params: SetReadMarkersTask.Params) {
|
override suspend fun execute(params: SetReadMarkersTask.Params) = withContext(coroutineDispatchers.io) {
|
||||||
val markers = mutableMapOf<String, String>()
|
val markers = mutableMapOf<String, String>()
|
||||||
Timber.v("Execute set read marker with params: $params")
|
Timber.v("Execute set read marker with params: $params")
|
||||||
val latestSyncedEventId = latestSyncedEventId(params.roomId)
|
val latestSyncedEventId = latestSyncedEventId(params.roomId)
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package im.vector.app.core.session.clientinfo
|
package im.vector.app.core.session.clientinfo
|
||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -27,16 +28,19 @@ class DeleteUnusedClientInformationUseCase @Inject constructor(
|
|||||||
suspend fun execute(deviceInfoList: List<DeviceInfo>): Result<Unit> = runCatching {
|
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).
|
// 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)
|
if (deviceInfoList.isEmpty()) return Result.success(Unit)
|
||||||
|
val dispatcher = activeSessionHolder.getSafeActiveSession()?.coroutineDispatchers?.io
|
||||||
val expectedClientInfoKeyList = deviceInfoList.map { MATRIX_CLIENT_INFO_KEY_PREFIX + it.deviceId }
|
?: return@runCatching
|
||||||
activeSessionHolder
|
withContext(dispatcher) {
|
||||||
.getSafeActiveSession()
|
val expectedClientInfoKeyList = deviceInfoList.map { MATRIX_CLIENT_INFO_KEY_PREFIX + it.deviceId }
|
||||||
?.accountDataService()
|
activeSessionHolder
|
||||||
?.getUserAccountDataEventsStartWith(MATRIX_CLIENT_INFO_KEY_PREFIX)
|
.getSafeActiveSession()
|
||||||
?.map { it.type }
|
?.accountDataService()
|
||||||
?.subtract(expectedClientInfoKeyList.toSet())
|
?.getUserAccountDataEventsStartWith(MATRIX_CLIENT_INFO_KEY_PREFIX)
|
||||||
?.forEach { userAccountDataKeyToDelete ->
|
?.map { it.type }
|
||||||
activeSessionHolder.getSafeActiveSession()?.accountDataService()?.deleteUserAccountData(userAccountDataKeyToDelete)
|
?.subtract(expectedClientInfoKeyList.toSet())
|
||||||
}
|
?.forEach { userAccountDataKeyToDelete ->
|
||||||
|
activeSessionHolder.getSafeActiveSession()?.accountDataService()?.deleteUserAccountData(userAccountDataKeyToDelete)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,11 +322,10 @@ class RoomListViewModel @AssistedInject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun handleDeleteLocalRooms() {
|
private fun handleDeleteLocalRooms() {
|
||||||
val localRoomIds = session.roomService()
|
viewModelScope.launch(session.coroutineDispatchers.io) {
|
||||||
.getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) })
|
val localRoomIds = session.roomService()
|
||||||
.map { it.roomId }
|
.getRoomSummaries(roomSummaryQueryParams { roomId = QueryStringValue.Contains(RoomLocalEcho.PREFIX) })
|
||||||
|
.map { it.roomId }
|
||||||
viewModelScope.launch {
|
|
||||||
localRoomIds.forEach {
|
localRoomIds.forEach {
|
||||||
session.roomService().deleteLocalRoom(it)
|
session.roomService().deleteLocalRoom(it)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,9 @@ import im.vector.app.R
|
|||||||
import im.vector.app.core.resources.BuildMeta
|
import im.vector.app.core.resources.BuildMeta
|
||||||
import im.vector.app.core.utils.FirstThrottler
|
import im.vector.app.core.utils.FirstThrottler
|
||||||
import im.vector.app.features.displayname.getBestName
|
import im.vector.app.features.displayname.getBestName
|
||||||
|
import im.vector.app.features.session.coroutineScope
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
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.Session
|
||||||
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
import org.matrix.android.sdk.api.session.content.ContentUrlResolver
|
||||||
import org.matrix.android.sdk.api.session.getUserOrDefault
|
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.
|
* 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?) {
|
fun setCurrentRoom(roomId: String?) {
|
||||||
updateEvents {
|
val dispatcher = currentSession?.coroutineDispatchers?.io ?: return
|
||||||
val hasChanged = roomId != currentRoomId
|
val scope = currentSession?.coroutineScope ?: return
|
||||||
currentRoomId = roomId
|
scope.launch(dispatcher) {
|
||||||
if (hasChanged && roomId != null) {
|
updateEvents {
|
||||||
it.clearMessagesForRoom(roomId)
|
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.
|
* 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?) {
|
fun setCurrentThread(threadId: String?) {
|
||||||
updateEvents {
|
val dispatcher = currentSession?.coroutineDispatchers?.io ?: return
|
||||||
val hasChanged = threadId != currentThreadId
|
val scope = currentSession?.coroutineScope ?: return
|
||||||
currentThreadId = threadId
|
scope.launch(dispatcher) {
|
||||||
currentRoomId?.let { roomId ->
|
updateEvents {
|
||||||
if (hasChanged && threadId != null) {
|
val hasChanged = threadId != currentThreadId
|
||||||
it.clearMessagesForThread(roomId, threadId)
|
currentThreadId = threadId
|
||||||
|
currentRoomId?.let { roomId ->
|
||||||
|
if (hasChanged && threadId != null) {
|
||||||
|
it.clearMessagesForThread(roomId, threadId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user