-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace flattenParents with directParentName #6314
Replace flattenParents with directParentName #6314
Conversation
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.get("RoomSummaryEntity") | ||
?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAME, String::class.java) | ||
?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAME, "") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we migrate it as empty here, it seems like it automatically syncs on launch and updates the value with the corresponding space parent of each room
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's updated after each sync. Is there a need to set a default value.
*/ | ||
val flattenParents: List<RoomSummary> = emptyList(), | ||
val directParentName: String? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it be properly updated, if the parent name changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed this one, it properly updates
*/ | ||
val flattenParents: List<RoomSummary> = emptyList(), | ||
val directParentName: String? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ericdecanini this should be a list, you can have several direct parents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be a list of names, not just one. Or you could format it as a coma separated list, but just one is not correct
…flatten_with_direct_parent # Conflicts: # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo030.kt
…flatten_with_direct_parent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think directParentNames is properly cleared before re-computing hierarchy, so it looks like you are continously adding the names to it.
I don't think I have seen an update on the migration (? or i missed a commit)
Also why only display the last() parent, I think web displays them all
Also would be nice to add a new test for that |
Pushed a change to make it show all direct parents and clear on sync See |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the migration of the DB.
|
||
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.get("RoomSummaryEntity") | ||
?.addField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a List and not a String here, no? So use addRealmListField
. I cannot test the migration since I have another issue with the Auth DB. Will be fixed once develop is been merged to your branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yes! Did addRealmListField
initially but lost it during a dev merge
@@ -235,6 +235,8 @@ internal open class RoomSummaryEntity( | |||
if (value != field) field = value | |||
} | |||
|
|||
var directParentNames: RealmList<String> = RealmList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but If there is no set
fun, this could be moved to the constructor.
@@ -207,9 +207,9 @@ class RoomSummaryItemFactory @Inject constructor( | |||
|
|||
private fun getSearchResultSubtitle(roomSummary: RoomSummary): String { | |||
val userId = roomSummary.directUserId | |||
val spaceName = roomSummary.flattenParents.lastOrNull()?.name | |||
val directParent = roomSummary.directParentNames.takeIf { it.isNotEmpty() }?.joinToString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please ensure parity with web to display parents in results.
and add a test in SpaceHierarchyTest
…flatten_with_direct_parent
…flatten_with_direct_parent # Conflicts: # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo032.kt # vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderGroup.kt # vector/src/main/java/im/vector/app/features/home/room/list/RoomListSectionBuilderSpace.kt
…flatten_with_direct_parent # Conflicts: # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/RealmSessionStoreMigration.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good except migration tests, not sure if we really need them
import org.matrix.android.sdk.internal.database.model.RoomSummaryEntityFields | ||
import org.matrix.android.sdk.test.fakes.FakeDynamicRealm | ||
|
||
internal class MigrateSessionTo033Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tests for Realm migrations are excessive. Migration classes never change, so there is no need to retest them, but we put extra work on our CI to run this tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests removed
…flatten_with_direct_parent # Conflicts: # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo033.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a quick test, so ok now when CI happy
0 -> null | ||
1 -> directParentNames.first() | ||
2 -> stringProvider.getQuantityString(R.plurals.search_space_parents, 1, directParentNames[0], directParentNames[1]) | ||
else -> stringProvider.getQuantityString(R.plurals.search_space_parents, size - 1, directParentNames[0], directParentNames.size - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could use size
instead of directParentNames.size
,
<plurals name="search_space_parents"> | ||
<item quantity="one">%1$s and %2$s</item> | ||
<item quantity="other">%1$s and %2$d others</item> | ||
</plurals> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct way to handle plurals, it can lead to errors with translations.
Also the resource name is a bit strange to me
You must have something like:
<strings name="search_space_two parents">%1$s and %2$s</string>
<plurals name="search_space_parents">
<item quantity="one">%1$s and %2$d other</item>
<item quantity="other">%1$s and %2$d others</item>
</plurals>
This is managed the same way for room_displayname_two_members
if you want to have a look on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update.
Please fix the conflict by creating a MigrateSessionTo035.kt
.
…flatten_with_direct_parent # Conflicts: # matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/database/migration/MigrateSessionTo034.kt
override fun doMigrate(realm: DynamicRealm) { | ||
realm.schema.get("RoomSummaryEntity") | ||
?.addRealmListField(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, String::class.java) | ||
?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You did not test the migration. The app is crashing.
The correct code is
?.transform { it.setString(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, "") } | |
?.transform { it.setList(RoomSummaryEntityFields.DIRECT_PARENT_NAMES.`$`, RealmList("")) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swear I tested this. Maybe the way I was testing it didn't actually cause this migration to happen
SonarCloud Quality Gate failed. |
Type of change
Content
Replaces flattenParents field in RoomSummary with directParentName to increase performance
Motivation and context
Previously to have the space parent displayed in the search screen, we added the
flattenParents
field toRoomSummary
, but using this was triggering a double mapping of the room summary and its parents thus affecting performance.To alleviate this, we decided on simply saving the parents name directly in
RoomSummaryUpdater
. This has little if any impact on performance and allows us to achieve the same goal without double mapping.Screenshots / GIFs
Tests
Preferably before doing this, change the build version so a clean install doesn't happen and you can test the migration too
Run the app and see that the search screen displays with spaces showing their space parent (if any) and performance isn't a problem
Tested devices
Checklist