Offline Mode: Sync Engine#22899
Conversation
Generated by 🚫 Danger |
|
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr22899-15f930e | |
| Version | 24.5 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 15f930e | |
| App Center Build | WPiOS - One-Offs #9339 |
|
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr22899-15f930e | |
| Version | 24.5 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 15f930e | |
| App Center Build | jetpack-installable-builds #8383 |
| } | ||
|
|
||
| // TODO: Replace with a new flag | ||
| @objc var isSyncNeeded: Bool { |
There was a problem hiding this comment.
I'm planning to add a new flag to the database but only after we merge the changes in trunk and after 24.6 is cut. We'll be also removing some data.
| // MARK: - Content Preview | ||
|
|
||
| fileprivate func buildContentPreview() { | ||
| if let excerpt = mt_excerpt, excerpt.count > 0 { |
There was a problem hiding this comment.
This was buggy and not effective as it would constantly reset.
| } | ||
|
|
||
| + (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost inContext:(NSManagedObjectContext *)managedObjectContext overwrite:(BOOL)overwrite { | ||
| if ([RemoteFeature enabled:RemoteFeatureFlagSyncPublishing] && (post.revision != nil && !overwrite)) { |
There was a problem hiding this comment.
If there are local revision, only sync (and trash in the future) should be able to update the post with the remote changes. I'm planning to simplify this code a bit later when we remove the feature flag.
| } | ||
| } | ||
|
|
||
| func performEditorAction(_ action: PostEditorAction, analyticsStat: WPAnalyticsStat?) { |
There was a problem hiding this comment.
This change should probably not be part of this PR, but it's too late too change. I suggest we roll forward and continue working on it in the future PRs. It's in the branch ,so it's safe.
|
|
||
| assert(post.latest() == post, "Must be opened with the latest verison of the post") | ||
|
|
||
| if !(post.isRevision() && !post.isSyncNeeded) { |
There was a problem hiding this comment.
This check is needed only for a scenario where the app crashes during editor – it will be covered later. I plan to re-open the editor automatically to make sure the user either commits of discard the revision.
| return | ||
| if RemoteFeatureFlag.syncPublishing.enabled() { | ||
| // Return early if a post is still uploading when the editor's requested. | ||
| guard !PostCoordinator.shared.isUpdating(post) else { |
There was a problem hiding this comment.
Not great naming – will probably rework later once we start tearing the old code out.
| let updatedIndexPaths = (tableView.indexPathsForVisibleRows ?? []).filter { | ||
| let post = fetchResultsController.object(at: $0) | ||
| return updatedObjects.contains(post) | ||
| return updatedObjects.contains(post) || updatedObjects.contains(post.original()) |
There was a problem hiding this comment.
The height no longer changes, so we should now move the notification observer to the cell itself, which will be safer
momo-ozawa
left a comment
There was a problem hiding this comment.
If you save a new draft, then reopen the editor, the "Update" button is enabled from the get go. It should only be enabled if the user makes any changes.
Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-03-28.at.18.41.30.mp4
When testing offline mode, the app crashes when the wifi reconnects. I waited for the "Offline changes" to appear in the post list cell, then reconnected the wifi, at which point the app crashed
It's been fixed in the newer PR where it now displays a "Publish" button #22913
Good catch. I only tested it once on a real device and it somehow worked. I think it was because I didn't have a debugger attached, so it didn't trigger a Core Data concurrency error. Fixed. |
051bebf to
8078ab5
Compare
8078ab5 to
e11aa84
Compare
| } | ||
| self.postEditorStateContext.updated(isBeingPublished: false) | ||
| SVProgressHUD.dismiss() | ||
| PostCoordinator.shared.save(post, defaultFailureNotice: uploadFailureNotice(action: action)) { [weak self] result in |
There was a problem hiding this comment.
Reverting this change as we are now handling the feature flag on a higher level – at the button tap.
momo-ozawa
left a comment
There was a problem hiding this comment.
Thanks for addressing the issues from my previous review! Reconnecting doesn't crash anymore 👍


This PR introduces a new sync engine for draft posts (see
PostCoordinator.setNeedsSync(for:)and the related methods).There are a lot of additions, but it's mostly unit tests.
The unit test target has some unrelated failures due to the WordPressKit update. I'll need to merge
trunkin order to fix it andtrunkneeds this change to be merged #22900 first.Architecture
Data
When you open an editor, it now always creates a new revision. For example:
The editor works with
R2. The previous revisions are immutable.The app not longer uses the existing
remoteStatusproperty. Instead, it uses a simpleisSyncNeededboolean to determine which revisions to sync.This amount of data is just enough to implement nearly any sync algorithm and to also fix issues like #21940.
Sync
PostCoordinatorperiodically syncs the revisions that have aisSyncNeededflag set totrue. It uses the newPostRepository.syncmethod introduces in the previous PRs. It creates a diff between the original and the most recent revision that needs sync, and uploads the changes using partial updates.Known Issues
.notConnectedToInternet, the app doesn't display the "offline changes" label and doesn't perform quick retriesTesting
The changes were tested only using REST APIs and only using a simplest scenarios where you edit a post and then tap "back" to save or discard changes. The remaining flows will be updated in the future PRs.
Discard changes (new draft)
Discard changes (existing draft)
Discard changes (fix #21940)
Follow the steps from the issue #21940 and verify that it no longer reproduces.
Create new post with image
Creating and updating unsynced a draft
/post/newOffline mode
Precondition: you are offline.
Offline mode and restart
Sync failure and retry
Precondition: request fails for any reason other than "404"
Discarded images
Regression Notes
PR submission checklist:
RELEASE-NOTES.txtif necessary.Testing checklist: