WordPress-iOS
WordPress-iOS copied to clipboard
Improve performance of Image and Gallery block processors to avoid long delay when saving a post
Fixes https://github.com/wordpress-mobile/gutenberg-mobile/issues/6696.
[!NOTE] Uses the changes from https://github.com/wordpress-mobile/WordPress-iOS/pull/22886.
To test
Delay when saving a post
- Create a post.
- Add a Gallery block and insert multiple images.
- Wait until all uploads finish.
- Close the editor and save the post.
- Observe the editor closes quickly with no significant delay.
- Re-open the post.
- Add more images.
- Repeat steps 3, 4.
- Observe the editor closes quickly with no significant delay.
Block processors
Follow the testing instructions to cover the functionality related to the processors for each block:
-
Gallery block:
-
Image Block:
Regression Notes
-
Potential unintended areas of impact The block processors are only used when saving a post. No other area should be impacted.
-
What I did to test those areas of impact (or what existing automated tests I relied on) Manually tested saving a post with different blocks. Additionally, each processor has its own unit test that has been verified.
-
What automated tests I added (or what prevented me from doing so) N/A
PR submission checklist:
- [x] I have completed the Regression Notes.
- [ ] I have considered adding unit tests for my changes.
- [ ] I have considered adding accessibility improvements for my changes.
- [x] I have considered if this change warrants user-facing release notes and have added them to
RELEASE-NOTES.txtif necessary.
Testing checklist:
- [ ] WordPress.com sites and self-hosted Jetpack sites.
- [ ] Portrait and landscape orientations.
- [ ] Light and dark modes.
- [ ] Fonts: Larger, smaller and bold text.
- [ ] High contrast.
- [ ] VoiceOver.
- [ ] Languages with large words or with letters/accents not frequently used in English.
- [ ] Right-to-left languages. (Even if translation isnβt complete, formatting should still respect the right-to-left layout)
- [ ] iPhone and iPad.
- [ ] Multi-tasking: Split view and Slide over. (iPad)
π² You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr22896-7694cb2 | |
| Version | 24.9 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 7694cb27bc4f662a08faa6745d40c2e67f9577a4 | |
| App Center Build | WPiOS - One-Offs #9957 |
π² You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr22896-7694cb2 | |
| Version | 24.9 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 7694cb27bc4f662a08faa6745d40c2e67f9577a4 | |
| App Center Build | jetpack-installable-builds #9007 |
I'm moving this to the next milestone since this is not a blocker, and the code freeze will be completed today.
π Hey @fluiddot, I'm bumping this PR to 24.8 since it's code freeze day. If this PR needs to target 24.7, please target the release branch once it's been cut. Thanks!
Hi @fluiddot π , I'm bumping this PR's milestone to 24.9 since I'm starting code freeze. Feel free to re-target this to the release branch if this is a blocker or intended for 24.8.
Hey @fluiddot, I'm bumping the milestone for this PR to 25.0 as I'm starting the code freeze. If this PR needs to go into 24.9, please go ahead and re-target it to the release branch.
π Hey @fluiddot, I'd like to pull in trunk on this PR as some time has passed. I believe this patch resolves the conflict on PostCoordinator.swift but I'd like for you to verify if possible. Thanks!
diff --cc WordPress/Classes/Services/PostCoordinator.swift
index 7098c95cae,2ea04cc472..0000000000
--- a/WordPress/Classes/Services/PostCoordinator.swift
+++ b/WordPress/Classes/Services/PostCoordinator.swift
@@@ -203,15 -741,7 +736,16 @@@ class PostCoordinator: NSObject
completion(.success(post))
}
+ func updateMediaBlocksBeforeSave(in post: AbstractPost, with media: Set<Media>) {
+ guard let postContent = post.content else {
+ return
+ }
+ let contentParser = GutenbergContentParser(for: postContent)
+ media.forEach { self.updateReferences(to: $0, in: contentParser.blocks, post: post) }
+ post.content = contentParser.html()
+ }
+
+ // - warning: deprecated (kahu-offline-mode)
func cancelAnyPendingSaveOf(post: AbstractPost) {
removeObserver(for: post)
}
@@@ -347,12 -879,18 +883,19 @@@
switch state {
case .ended:
let successHandler = {
- self.updateReferences(to: media, in: post)
+ self.updateMediaBlocksBeforeSave(in: post, with: [media])
+
- // Let's check if media uploading is still going, if all finished with success then we can upload the post
- if !self.mediaCoordinator.isUploadingMedia(for: post) && !post.hasFailedMedia {
- self.removeObserver(for: post)
- completion(.success(post))
+ if self.isSyncPublishingEnabled {
+ if post.media.allSatisfy({ $0.remoteStatus == .sync }) {
+ self.removeObserver(for: post)
+ completion(.success(post))
+ }
+ } else {
+ // Let's check if media uploading is still going, if all finished with success then we can upload the post
+ if !self.mediaCoordinator.isUploadingMedia(for: post) && !post.hasFailedMedia {
+ self.removeObserver(for: post)
+ completion(.success(post))
+ }
}
}
switch media.mediaType {
π Hey @fluiddot, I'd like to pull in
trunkon this PR as some time has passed. I believe this patch resolves the conflict onPostCoordinator.swiftbut I'd like for you to verify if possible. Thanks!
Yes @twstokes, your patch contains the same conflict resolution I have in mind. I've solved it in https://github.com/wordpress-mobile/WordPress-iOS/pull/22896/commits/ccffe5bdbb1b110f780ca5bcc44bf05d9117a758.
It looks like a unit test may be failing because the output changed. I'm only spotting a whitespace difference.
@fluiddot do you think we're good to just update the expected output?
It looks like a unit test may be failing because the output changed. I'm only spotting a whitespace difference.
@fluiddot do you think we're good to just update the expected output?
@twstokes Yep, the difference is the extra whitespace at the end of the figure tag. The whitespace is only necessary to conform the xhtml specs for self-closing tags, which is not the case here as we are processing HTML. However, as commented in the parser's code (SwiftSoup), seems the same formatting is used to for compatibility. Hence, this extra whitespace is expected in the output. I've pushed a fix in https://github.com/wordpress-mobile/WordPress-iOS/pull/22896/commits/3a22f64bf5dc303879de9d39c990d89bd9ef9320.
LGTM @fluiddot! Feel free to merge - I only shared some Swift styling thoughts. π
Thanks @twstokes for reviewing and approving the PR π ! I've applied the suggestions you shared and enabled auto-merge.