-
Notifications
You must be signed in to change notification settings - Fork 817
Post Images from blocks: move from parse_blocks to Block_Delimiter #43662
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
base: trunk
Are you sure you want to change the base?
Conversation
Following #43648, we can start using the new class to parse blocks. Internal reference: p7H4VZ-5l1-p2
0db85a4
to
2b192ca
Compare
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
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.
Pull Request Overview
This PR refactors the post image extraction to use the new Block_Delimiter class for parsing Gutenberg blocks, aiming for performance improvements without changing existing functionality.
- Adds
automattic/block-delimiter
as a dependency and updatescomposer.json
- Rewrites
from_blocks()
to scan withBlock_Delimiter
and introducesget_images_from_block_attributes()
- Removes the old recursive
parse_blocks()
logic and utility methods, and adds a changelog entry
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
projects/plugins/jetpack/tests/php/media/Jetpack_PostImages_Test.php | Minor whitespace change in test imports |
projects/plugins/jetpack/composer.json | Added automattic/block-delimiter dependency |
projects/plugins/jetpack/class.jetpack-post-images.php | Refactored from_blocks() to use Block_Delimiter , removed old parsing logic, added get_images_from_block_attributes() |
projects/plugins/jetpack/changelog/add-block-delimiter-post-iamges | New changelog entry for performance enhancement |
Comments suppressed due to low confidence (2)
projects/plugins/jetpack/changelog/add-block-delimiter-post-iamges:0
- Rename the changelog file to
add-block-delimiter-post-images
to correct the spelling.
Filename contains a typo: "iamges" should be "images"
projects/plugins/jetpack/class.jetpack-post-images.php:454
- Add or update unit tests to cover the new
Block_Delimiter::scan_delimiters
path and theget_images_from_block_attributes()
method to ensure coverage of the refactored block parsing logic.
foreach ( Block_Delimiter::scan_delimiters( $html_info['html'] ) as $where => $delimiter ) {
Code Coverage SummaryCoverage changed in 1 file.
|
Proposed changes:
Following #43648, we can start using the new class to parse blocks.
This should not change anything in the existing functionality, but should improve performance.
Performance-wise, there are gains when comparing the time to fetch images with the 2 methods, although they are minimal with this change alone.
For reference, measuring speed for a post based off this long post's contents, with added galleries, single images, slideshows, stories, tiled galleries, groups:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
Jetpack_PostImages
does not pick images from attachments to your post)https://herve.bzh/wp-content/uploads/2013/01/watson-5818-1.jpg
: