-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve performance of Image and Gallery block processors to avoid long delay when saving a post #22896
Conversation
|
App Name | ![]() |
|
Configuration | Release-Alpha | |
Build Number | pr22896-7694cb2 | |
Version | 24.9 | |
Bundle ID | org.wordpress.alpha | |
Commit | 7694cb2 | |
App Center Build | WPiOS - One-Offs #9957 |
6613f88
to
af3c5ad
Compare
|
App Name | ![]() |
|
Configuration | Release-Alpha | |
Build Number | pr22896-7694cb2 | |
Version | 24.9 | |
Bundle ID | com.jetpack.alpha | |
Commit | 7694cb2 | |
App Center Build | jetpack-installable-builds #9007 |
@@ -188,26 +188,30 @@ class PostCoordinator: NSObject { | |||
} | |||
|
|||
// Ensure that all synced media references are up to date | |||
post.media.forEach { media in |
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.
Please be cautious about making changes to PostCoordinator
because the large potion of it is or will be rewritten. prepareToSave
is unchanged, so it's a safe change.
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 @kean for the call out 🙇 ! This PR mainly focuses on the logic related to processing blocks before saving a post, which requires touching up some bits of the PostCoordinator
. I'm planning to modify only necessary here, so hopefully there won't be much conflict with ongoing changes. In any case, I'll be happy to contribute to the new version by applying the same updates.
var gutenbergBlockProcessors: [GutenbergProcessor] = [] | ||
var gutenbergProcessors: [Processor] = [] |
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.
The idea is to update gradually the processors to adopt the new GutenbergContentParser
. In the meantime, we'll have two different processors.
import Aztec | ||
import SwiftSoup |
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.
Aztec was imported in this file to use HTMLProcessor
. Now the HTML processing is performed by using SwiftSoup
.
<br />Asf fasd fas | ||
<br />A sdfasdf sadf | ||
<br /> Asdf</figcaption> |
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.
SwiftSoup
always closes tags, so tags like br
or hr
will be converted.
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 |
Hey @fluiddot, I'm bumping the milestone for this PR to |
👋 Hey @fluiddot, I'd like to pull in 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 { |
# Conflicts: # WordPress/Classes/Services/PostCoordinator.swift
Yes @twstokes, your patch contains the same conflict resolution I have in mind. I've solved it in ccffe5b. |
…-blocks-processor
…essor' into update/improve-file-block-processor
@twstokes Yep, the difference is the extra whitespace at the end of the |
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 @fluiddot! Feel free to merge - I only shared some Swift styling thoughts. 🚀
} | ||
_ = try? imgTag.attr("src", self.remoteURLString) | ||
_ = try? imgTag.attr("class", newImgClassAttributes) | ||
_ = try? imgTag.attr(ImageKeys.dataID, "\(self.serverMediaID)") |
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.
Optional nit and more of a personal pref, but it may be more common to convert the Int -> String via String(self.serverMediaID)
if you're not interpolating anything else.
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 applied this suggestion in 7694cb2.
return html | ||
}) | ||
let dataLinkAttribute = try? imgTag.attr(ImageKeys.dataLink) | ||
if dataLinkAttribute != nil { |
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.
Same comment about adding an if let
or guarding
to remove the optional.
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 applied this suggestion in d60c1d1.
let imgUploadID = Int32(imageIDString) | ||
func processImgTags(_ block: GutenbergParsedBlock) { | ||
let imgTags = try? block.elements.select("img") | ||
imgTags?.forEach { img in |
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.
Same comment about adding an if let
or guarding
to remove the optional.
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 applied this suggestion in d60c1d1.
return nil | ||
} | ||
func processLinkPostMediaUpload(_ block: GutenbergParsedBlock) { | ||
let aTags = try? block.elements.select(LinkKeys.name) |
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.
Same comment about adding an if let
or guarding
to remove the optional.
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 applied this suggestion in d60c1d1.
} | ||
func processImgPostMediaUpload(_ element: Element) { | ||
let imgTags = try? element.select(ImageKeys.name) | ||
imgTags?.forEach {imgTag in |
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.
Optional nit: Could be in an if let
, or could guard
and return early to remove the optional.
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 applied this suggestion in d60c1d1.
Fixes wordpress-mobile/gutenberg-mobile#6696.
Note
Uses the changes from #22886.
To test
Delay when saving a post
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:
RELEASE-NOTES.txt
if necessary.Testing checklist: