-
Notifications
You must be signed in to change notification settings - Fork 211
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
Run offline state sync in the background #3367
Conversation
4e4b18b
to
3ad3ed3
Compare
Generated by 🚫 Danger |
SDK Size
|
SDK Performance
|
SDK Size
|
8831244
to
4884f7a
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.
LGTM! ✅ Nice that this is behind a flag so that we can minimize the risk on this one 👍
4884f7a
to
f184d6e
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.
Looks good to me ✅ We should do solid testing here @testableapple
/// For *internal use* only | ||
/// | ||
/// Uses version 2 for offline state sync. | ||
public static var _isSyncV2Enabled = true |
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.
We should also have a ticket to remove this in 2-3 releases and only support V2.
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.
Added a ticket
// | ||
if config.isLocalStorageEnabled { | ||
apiClient.enterRecoveryMode() | ||
operations.append(ExecutePendingOfflineActions(offlineRequestsRepository: offlineRequestsRepository)) |
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 assume there are no changes in this logic, right? We have some logic for sending new messages - after some interval they shouldn't be sent when you come online. Just making sure we still have that.
/// 1. Collect all the **active** channel ids (from instances of `Chat`, `ChannelList`, `ChatChannelController`, `ChatChannelListController`) | ||
/// 2. Apply updates from the /sync endpoint for these channels | ||
/// 3. Refresh channel lists (channels for current pages in `ChannelList`, `ChatChannelListController`) | ||
private func syncLocalStateV2(lastSyncAt: Date, completion: @escaping () -> Void) { |
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.
We also have some internal docs about the sync mechanism, that probably require revisiting.
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 is still there, that logic is in OfflineRequestsRepository
what did not change.
c1d523f
to
a201597
Compare
Quality Gate passedIssues Measures |
* main: (154 commits) Unblock release on workflow dispatch (GetStream#3389) [CI] Run release action on workflow dispatch (GetStream#3386) [CI] Do not unshallow branches on CI [CI] Do not unshallow branches on CI [CI] Update git config on merging develop and release branches [CI] Update git config on merging develop and release branches [CI] Pull origin release branch on release [CI] Pull origin release branch on release [CI] Fetch all branches on release (GetStream#3385) [CI] Fetch all branches on release (GetStream#3385) Bump 4.62.0 Store pending message along with regular messages (GetStream#3378) [CI] Set up a default base branch when automatically creating PRs (GetStream#3383) Fix reading the local database state just after the initial write (GetStream#3373) [CI] Add space to SDK size badge (GetStream#3379) Update channel type documentation to reflect allowed characters (GetStream#3377) Reuse CurrentChatUserController instead of recreating it when sending typing events (GetStream#3372) Run offline state sync in the background (GetStream#3367) [CI] Bump fastlane plugin version (GetStream#3376) [CI] Bump fastlane actions plugin (GetStream#3375) ...
🔗 Issue Links
Resolves PBE-4293
Resolves stream-chat-swift/issues/2021
🎯 Goal
Allow regular API calls to be made while offline sync is running which gives quicker UI updates when UI update requires API call to finish.
📝 Summary
StreamRuntimeCheck._isSyncV2Enabled
🛠 Implementation
Adds a new version of the offline state sync which only pauses regular API requests when handling automatic retries. The sync is more lightweight and only syncs currently active channels (active = server state has been requested in this session aka calling synchronize). If sync is not possible (too many events), then data is fully refreshed for active channel lists (same as synchronize but not resetting to the first page).
Improvements
Notes
syncExistingChannelsEvents
) which is triggered by theChatRemoteNotificationHandler
. This code path triggers therequest.fetchLimit = 100
case which the regular sync actually does not. We should look this in a separate task.Summary of the V2 mode
Recovery mode (pauses regular API requests while it is running)
Background mode (other regular API requests are allowed to run at the same time)
Chat
,ChannelList
,ChatChannelController
,ChatChannelListController
)2.a Apply changes
2.b When there are too many events, just refresh channel lists (channels for current pages in
ChannelList
,ChatChannelListController
)Comparison
🧪 Manual Testing Notes
Case 1: Channel list updates
Case 2: Sending messages while offline
Case 3: Not resetting channel list (#2021)
☑️ Contributor Checklist