Replaces flatten parents with direct parent name in RoomSummary

This commit is contained in:
ericdecanini 2022-06-15 11:46:57 +02:00
parent 163212554b
commit 385720b89d
12 changed files with 52 additions and 30 deletions

View File

@ -231,14 +231,11 @@ interface RoomService {
* @param queryParams The filter to use * @param queryParams The filter to use
* @param pagedListConfig The paged list configuration (page size, initial load, prefetch distance...) * @param pagedListConfig The paged list configuration (page size, initial load, prefetch distance...)
* @param sortOrder defines how to sort the results * @param sortOrder defines how to sort the results
* @param getFlattenParents When true, the list of known parents and grand parents summaries will be resolved.
* This can have significant impact on performance, better be used only on manageable list (filtered by displayName, ..).
*/ */
fun getFilteredPagedRoomSummariesLive( fun getFilteredPagedRoomSummariesLive(
queryParams: RoomSummaryQueryParams, queryParams: RoomSummaryQueryParams,
pagedListConfig: PagedList.Config = defaultPagedListConfig, pagedListConfig: PagedList.Config = defaultPagedListConfig,
sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY, sortOrder: RoomSortOrder = RoomSortOrder.ACTIVITY,
getFlattenParents: Boolean = false,
): UpdatableLivePageResult ): UpdatableLivePageResult
/** /**

View File

@ -164,9 +164,9 @@ data class RoomSummary(
*/ */
val spaceChildren: List<SpaceChildInfo>? = null, val spaceChildren: List<SpaceChildInfo>? = null,
/** /**
* List of all the space parents. Will be empty by default, you have to explicitly request it. * The name of the room's direct space parent if any
*/ */
val flattenParents: List<RoomSummary> = emptyList(), val directParentName: String? = null,
/** /**
* List of all the space parent Ids. * List of all the space parent Ids.
*/ */

View File

@ -47,6 +47,7 @@ import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo026
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo027 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo027
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo028 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo028
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo029 import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo029
import org.matrix.android.sdk.internal.database.migration.MigrateSessionTo030
import org.matrix.android.sdk.internal.util.Normalizer import org.matrix.android.sdk.internal.util.Normalizer
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
@ -95,5 +96,6 @@ internal class RealmSessionStoreMigration @Inject constructor(
if (oldVersion < 27) MigrateSessionTo027(realm).perform() if (oldVersion < 27) MigrateSessionTo027(realm).perform()
if (oldVersion < 28) MigrateSessionTo028(realm).perform() if (oldVersion < 28) MigrateSessionTo028(realm).perform()
if (oldVersion < 29) MigrateSessionTo029(realm).perform() if (oldVersion < 29) MigrateSessionTo029(realm).perform()
if (oldVersion < 30) MigrateSessionTo030(realm).perform()
} }
} }

View File

@ -106,6 +106,7 @@ internal class RoomSummaryMapper @Inject constructor(
worldReadable = it.childSummaryEntity?.joinRules == RoomJoinRules.PUBLIC worldReadable = it.childSummaryEntity?.joinRules == RoomJoinRules.PUBLIC
) )
}, },
directParentName = roomSummaryEntity.directParentName,
flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList(), flattenParentIds = roomSummaryEntity.flattenParentIds?.split("|") ?: emptyList(),
roomEncryptionAlgorithm = when (val alg = roomSummaryEntity.e2eAlgorithm) { roomEncryptionAlgorithm = when (val alg = roomSummaryEntity.e2eAlgorithm) {
// I should probably use #hasEncryptorClassForAlgorithm but it says it supports // I should probably use #hasEncryptorClassForAlgorithm but it says it supports

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.matrix.android.sdk.internal.database.migration
import io.realm.DynamicRealm
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields
import org.matrix.android.sdk.internal.util.database.RealmMigrator
internal class MigrateSessionTo030(realm: DynamicRealm) : RealmMigrator(realm, 30) {
override fun doMigrate(realm: DynamicRealm) {
realm.schema.get("RoomSummaryEntity")
?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAME, String::class.java)
?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAME, "") } // TODO: make this get the direct parent name
}
}

View File

@ -235,6 +235,11 @@ internal open class RoomSummaryEntity(
if (value != field) field = value if (value != field) field = value
} }
var directParentName: String? = null
set(value) {
if (value != field) field = value
}
var flattenParentIds: String? = null var flattenParentIds: String? = null
set(value) { set(value) {
if (value != field) field = value if (value != field) field = value

View File

@ -140,9 +140,8 @@ internal class DefaultRoomService @Inject constructor(
queryParams: RoomSummaryQueryParams, queryParams: RoomSummaryQueryParams,
pagedListConfig: PagedList.Config, pagedListConfig: PagedList.Config,
sortOrder: RoomSortOrder, sortOrder: RoomSortOrder,
getFlattenParents: Boolean
): UpdatableLivePageResult { ): UpdatableLivePageResult {
return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder, getFlattenParents) return roomSummaryDataSource.getUpdatablePagedRoomSummariesLive(queryParams, pagedListConfig, sortOrder)
} }
override fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData<Int> { override fun getRoomCountLive(queryParams: RoomSummaryQueryParams): LiveData<Int> {

View File

@ -200,14 +200,13 @@ internal class RoomSummaryDataSource @Inject constructor(
queryParams: RoomSummaryQueryParams, queryParams: RoomSummaryQueryParams,
pagedListConfig: PagedList.Config, pagedListConfig: PagedList.Config,
sortOrder: RoomSortOrder, sortOrder: RoomSortOrder,
getFlattenedParents: Boolean = false
): UpdatableLivePageResult { ): UpdatableLivePageResult {
val realmDataSourceFactory = monarchy.createDataSourceFactory { realm -> val realmDataSourceFactory = monarchy.createDataSourceFactory { realm ->
roomSummariesQuery(realm, queryParams).process(sortOrder) roomSummariesQuery(realm, queryParams).process(sortOrder)
} }
val dataSourceFactory = realmDataSourceFactory.map { val dataSourceFactory = realmDataSourceFactory.map {
roomSummaryMapper.map(it) roomSummaryMapper.map(it)
}.map { if (getFlattenedParents) it.getWithParents() else it } }
val boundaries = MutableLiveData(ResultBoundaries()) val boundaries = MutableLiveData(ResultBoundaries())
@ -246,13 +245,6 @@ internal class RoomSummaryDataSource @Inject constructor(
} }
} }
private fun RoomSummary.getWithParents(): RoomSummary {
val parents = flattenParentIds.mapNotNull { parentId ->
getRoomSummary(parentId)
}
return copy(flattenParents = parents)
}
fun getCountLive(queryParams: RoomSummaryQueryParams): LiveData<Int> { fun getCountLive(queryParams: RoomSummaryQueryParams): LiveData<Int> {
val liveRooms = monarchy.findAllManagedWithChanges { val liveRooms = monarchy.findAllManagedWithChanges {
roomSummariesQuery(it, queryParams) roomSummariesQuery(it, queryParams)

View File

@ -366,24 +366,20 @@ internal class RoomSummaryUpdater @Inject constructor(
.forEach { entry -> .forEach { entry ->
val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst() val parent = RoomSummaryEntity.where(realm, entry.key.roomId).findFirst()
if (parent != null) { if (parent != null) {
// Timber.v("## SPACES: check hierarchy of ${parent.name} id ${parent.roomId}")
// Timber.v("## SPACES: flat known parents of ${parent.name} are ${flattenSpaceParents[parent.roomId]}")
val flattenParentsIds = (flattenSpaceParents[parent.roomId] ?: emptyList()) + listOf(parent.roomId) val flattenParentsIds = (flattenSpaceParents[parent.roomId] ?: emptyList()) + listOf(parent.roomId)
// Timber.v("## SPACES: flatten known parents of children of ${parent.name} are ${flattenParentsIds}")
entry.value.forEach { child -> entry.value.forEach { child ->
RoomSummaryEntity.where(realm, child.roomId).findFirst()?.let { childSum -> RoomSummaryEntity.where(realm, child.roomId).findFirst()?.let { childSum ->
childSum.directParentName = parent.displayName()
// Timber.w("## SPACES: ${childSum.name} is ${childSum.roomId} fc: ${childSum.flattenParentIds}") if (childSum.flattenParentIds == null) {
// var allParents = childSum.flattenParentIds ?: "" childSum.flattenParentIds = ""
if (childSum.flattenParentIds == null) childSum.flattenParentIds = "" }
flattenParentsIds.forEach { flattenParentsIds.forEach {
if (childSum.flattenParentIds?.contains(it) != true) { if (childSum.flattenParentIds?.contains(it) != true) {
childSum.flattenParentIds += "|$it" childSum.flattenParentIds += "|$it"
} }
} }
// childSum.flattenParentIds = "$allParents|"
// Timber.v("## SPACES: flatten of ${childSum.name} is ${childSum.flattenParentIds}")
} }
} }
} }

View File

@ -71,7 +71,7 @@ class RoomListSectionBuilderGroup(
}, },
{ qpm -> { qpm ->
val name = stringProvider.getString(R.string.bottom_action_rooms) val name = stringProvider.getString(R.string.bottom_action_rooms)
val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm, getFlattenParents = true) val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(qpm)
onUpdatable(updatableFilterLivePageResult) onUpdatable(updatableFilterLivePageResult)
val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow()

View File

@ -332,7 +332,7 @@ class RoomListSectionBuilderSpace(
}, },
{ queryParams -> { queryParams ->
val name = stringProvider.getString(R.string.bottom_action_rooms) val name = stringProvider.getString(R.string.bottom_action_rooms)
val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams, getFlattenParents = true) val updatableFilterLivePageResult = session.roomService().getFilteredPagedRoomSummariesLive(queryParams)
onUpdatable(updatableFilterLivePageResult) onUpdatable(updatableFilterLivePageResult)
val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow() val itemCountFlow = updatableFilterLivePageResult.livePagedList.asFlow()

View File

@ -206,10 +206,10 @@ class RoomSummaryItemFactory @Inject constructor(
.itemClickListener { onClick?.invoke(roomSummary) } .itemClickListener { onClick?.invoke(roomSummary) }
private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { private fun getSearchResultSubtitle(roomSummary: RoomSummary): String {
val userId = roomSummary.directUserId val userId = roomSummary.directParentName
val spaceName = roomSummary.flattenParents.lastOrNull()?.name val directParent = roomSummary.directParentName
val canonicalAlias = roomSummary.canonicalAlias val canonicalAlias = roomSummary.canonicalAlias
return (userId ?: spaceName ?: canonicalAlias).orEmpty() return (userId ?: directParent ?: canonicalAlias).orEmpty()
} }
} }