Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog.d/8454.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix several performance issues causing app non responsive issues.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
}
Expand All @@ -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)
}
}
}
}
Expand Down