Skip to content
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

Realm migration bg #6548

Merged
merged 8 commits into from
Jul 21, 2022
Merged

Realm migration bg #6548

merged 8 commits into from
Jul 21, 2022

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Jul 13, 2022

This PR tries to move the Realm migration DB into background.

The first commit ensure there is always a migration to do and the migration will last 5 minutes. To be dropped of course.

Before - migration in VectorApplication.onCreate() After - migration in MainActivity view model
DbMigrationInFg DbMigrationInBg

New design with a wording (will iterate with @ganfra ):

image

Before we can have ANR if the migration takes time. After this should not happen anymore.

I create the PR to make this work public.

There are still some limitations:

  • the code is quite dirty.
  • we should consider using a mono Activity pattern to avoid some UI side effect when opening the app from a notification, after the app has been killed.
  • deep links management are not handled yet
  • ShareActivity management
  • Notification intent management
  • Handle the todo : TODO This will not work, handle this case.
  • probably some remaining crashes...

if (intent.hasExtra(EXTRA_NEXT_INTENT)) {
// Start the next Activity
val nextIntent = intent.getParcelableExtra<Intent>(EXTRA_NEXT_INTENT)
startIntentAndFinish(nextIntent)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is working but when going back, we can see the MainActivity screen for a few ms...

@bmarty bmarty force-pushed the feature/bma/realm_migration_bg branch from 9ec5de1 to ef41a3d Compare July 15, 2022 15:22
@bmarty bmarty requested a review from ganfra July 18, 2022 13:19
@bmarty bmarty force-pushed the feature/bma/realm_migration_bg branch 2 times, most recently from e5c1c63 to 7288f37 Compare July 19, 2022 16:14
Copy link
Member

@ganfra ganfra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 small remarks, otherwise LGTM. Not tested.

private fun startPollingActiveSession() {
globalScope.launch {
do {
delay(1.seconds.inWholeMilliseconds)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a listener to tell when the session is ready instead of polling?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but I think this is not necessary because it will make the ActiveSessionHolder more complex for not real added value

clearNotifications()

startAppViewModel.onEach {
renderState(it)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will refresh the UI every second, maybe not necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at the beginning I wanted to add more complex UI (timer, different wording depending on the duration, etc.). I may iterate on this, but honestly does it really worth it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done it in 912d71b

@bmarty bmarty force-pushed the feature/bma/realm_migration_bg branch from 912d71b to 6314a2f Compare July 21, 2022 08:25
@bmarty bmarty marked this pull request as ready for review July 21, 2022 08:25
@bmarty
Copy link
Member Author

bmarty commented Jul 21, 2022

OK. I have dropped the tmp commit and added a file for the changelog.
PR can be merged if CI is happy.

@bmarty bmarty enabled auto-merge July 21, 2022 08:27
@bmarty bmarty disabled auto-merge July 21, 2022 08:27
@bmarty bmarty enabled auto-merge July 21, 2022 08:30
…rApplication to unblock the main thread.

This fix is not necessary anymore, since the session is restored either in `MainActivity` or in `VectorMessagingReceiver`.
Ref: b7a54ea
It also fixes a crash when trying to share to the app if there is no active session: `IncomingShareViewModel` injects the `session` in the constructor.
@bmarty bmarty force-pushed the feature/bma/realm_migration_bg branch from cb73cfa to b83f6f2 Compare July 21, 2022 09:19
@sonarcloud
Copy link

sonarcloud bot commented Jul 21, 2022

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants