From b8eef9b19a0080b37a7b018b45a22abf08d54808 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 3 Jun 2022 14:21:03 +0200 Subject: [PATCH] fix slow paged room list --- .../org/matrix/android/sdk/api/session/room/RoomService.kt | 5 ++++- .../android/sdk/internal/session/room/DefaultRoomService.kt | 5 +++-- .../features/home/room/list/RoomListSectionBuilderGroup.kt | 2 +- .../features/home/room/list/RoomListSectionBuilderSpace.kt | 2 +- .../app/features/home/room/list/RoomSummaryItemFactory.kt | 4 +++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt index 0a495f3552..ea86d04a29 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/room/RoomService.kt @@ -227,11 +227,14 @@ interface RoomService { /** * TODO Doc. + * @param getFlattenParents When true, the list of known parent and grand parent summaries will be resolved. + * This can have significant impact on performance, better be used only on manageable list (filtered by displayName, ..). */ fun getFilteredPagedRoomSummariesLive( queryParams: RoomSummaryQueryParams, pagedListConfig: PagedList.Config = defaultPagedListConfig, - sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY + sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY, + getFlattenParents: Boolean = false, ): UpdatableLivePageResult /** diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt index 7a7804c354..63d4091167 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/DefaultRoomService.kt @@ -139,9 +139,10 @@ internal class DefaultRoomService @Inject constructor( override fun getFilteredPagedRoomSummariesLive( queryParams: RoomSummaryQueryParams, pagedListConfig: PagedList.Config, - sortOrder: RoomSortOrder + sortOrder: RoomSortOrder, + getFlattenedParents: Boolean ): UpdatableLivePageResult { - return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder, getFlattenedParents = true) + return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder, getFlattenedParents) } override fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData { diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt index 70fb6988e8..01fced6489 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt @@ -71,7 +71,7 @@ class RoomListSectionBuilderGroup( }, { qpm -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm, getFlattenParents = true) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt index 0e3f61e186..362c446115 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt @@ -332,7 +332,7 @@ class RoomListSectionBuilderSpace( }, { queryParams -> val name = stringProvider.getString(R.string.bottom_action_rooms) - val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams) + val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams, getFlattenParents = true) onUpdatable(updatableFilterLivePageResult) val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() diff --git a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt index 9601ccf914..0526af367a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/list/RoomSummaryItemFactory.kt @@ -207,7 +207,9 @@ class RoomSummaryItemFactory @Inject constructor( private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { val userId = roomSummary.directUserId - val spaceName = roomSummary.spaceParents?.firstOrNull()?.roomSummary?.name + val spaceName = roomSummary.flattenParents + .takeIf { it.isNotEmpty() } + ?.joinToString(", ") { it.name } val canonicalAlias = roomSummary.canonicalAlias return (userId ?: spaceName ?: canonicalAlias).orEmpty()