-
Notifications
You must be signed in to change notification settings - Fork 187
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
Create SyncOrchestrator
#4176
Create SyncOrchestrator
#4176
Conversation
📱 Scan the QR code below to install the build (arm64 only) for this PR. |
...sh/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/SyncOnNotifiableEvent.kt
Outdated
Show resolved
Hide resolved
396fe48
to
801dd62
Compare
appnav/src/main/kotlin/io/element/android/appnav/SyncObserver.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/LoggedInFlowNode.kt
Outdated
Show resolved
Hide resolved
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! Please see my comments.
...es/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt
Outdated
Show resolved
Hide resolved
features/login/impl/src/main/kotlin/io/element/android/features/login/impl/LoginFlowNode.kt
Outdated
Show resolved
Hide resolved
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.
Some remarks
.../matrix/api/src/main/kotlin/io/element/android/libraries/matrix/api/sync/SyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
...api/src/main/kotlin/io/element/android/libraries/matrix/api/sync/SyncOrchestratorProvider.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/MatrixClientsHolder.kt
Outdated
Show resolved
Hide resolved
@ganfra all the points should have been fixed in the latest commit. |
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.
LGTM, thanks!
…ugh the whole app. The decision is based on several inputs: sync state, network available, app in foreground, app in call, app needing to sync an event for a notification.
…fail instead This prevents an issue when using the offline mode of the SDK, which made the wrong UI states to be shown when the `SyncState` is `Idle` (that is, after the service being manually stopped).
…they're not easily mistaken with internet connectivity instead
3033b67
to
64abdf6
Compare
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.
A new bunch of comments, I have not run the code yet
appnav/src/main/kotlin/io/element/android/appnav/di/MatrixSessionCache.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/MatrixSessionCache.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/DefaultSyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
...sh/impl/src/main/kotlin/io/element/android/libraries/push/impl/push/SyncOnNotifiableEvent.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/DefaultSyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
initialSyncMutex.lock() | ||
|
||
combine( | ||
// small debounce to avoid spamming startSync when the state is changing quickly in case of error. |
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.
Maybe the debounced can be moved after the combine block (before .distinctUntilChanged())?
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 causes issues in the tests, since it's preventing some intermediate states from being generated. I'd rather keep it were it is, if possible.
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.
Can you try with this patch?
...rc/main/kotlin/io/element/android/services/appnavstate/test/FakeAppForegroundStateService.kt
Show resolved
Hide resolved
… the existing loop when offline mode is enabled for the Client in the SDK
… to it, remove the existing provider interface.
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.
Some more remarks
appnav/src/main/kotlin/io/element/android/appnav/di/DefaultSyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
appnav/src/test/kotlin/io/element/android/appnav/SyncOrchestratorTest.kt
Outdated
Show resolved
Hide resolved
appnav/src/test/kotlin/io/element/android/appnav/di/MatrixSessionCacheTest.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/MatrixSessionCache.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/SyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
…coroutine scope was being incorrectly injected instead.
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. I'll do more tests tomorrow. There are still some remarks that are not yet handled (some of them are old), maybe you missed them, this is just a kind reminder.
...ies/matrix/impl/src/main/kotlin/io/element/android/libraries/matrix/impl/RustMatrixClient.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/DefaultSyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/SyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
...api/src/main/kotlin/io/element/android/services/appnavstate/api/AppForegroundStateService.kt
Show resolved
Hide resolved
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.
I think the tests could be simplified a bit, now that we do not start an initial sync.
Then I believe that the PR can be merged to be in the latest nightly.
appnav/src/test/kotlin/io/element/android/appnav/SyncOrchestratorTest.kt
Outdated
Show resolved
Hide resolved
appnav/src/test/kotlin/io/element/android/appnav/SyncOrchestratorTest.kt
Outdated
Show resolved
Hide resolved
appnav/src/main/kotlin/io/element/android/appnav/di/SyncOrchestrator.kt
Outdated
Show resolved
Hide resolved
...api/src/main/kotlin/io/element/android/services/appnavstate/api/AppForegroundStateService.kt
Show resolved
Hide resolved
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 have found something, please wait before merging, I will comment
appnav/src/test/kotlin/io/element/android/appnav/SyncOrchestratorTest.kt
Show resolved
Hide resolved
appnav/src/test/kotlin/io/element/android/appnav/SyncOrchestratorTest.kt
Show resolved
Hide resolved
appnav/src/test/kotlin/io/element/android/appnav/SyncOrchestratorTest.kt
Show resolved
Hide resolved
|
Content
Centralise the start/stop sync logic in a single component of the app:
SyncOrchestrator
, which will act as the single point where sync start/stop can happen, based on several inputs (sync state, network available, app in foreground, app in call, app needing to sync an event for a notification).AppForegroundStateService
.SyncOrchestrator
.Motivation and context
Having too many points where the sync could be started and stopped could cause issues where the sync was unexpectedly stopped when it should instead be running or a deadlock may happen for several start/stop calls.
It should help with #4150
Tests
Just play with the sync state with network online/offline and app foreground state, receiving notifications, joining calls, etc.
Tested devices
Checklist