-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Ensure that post thumbnail is cached in latest post block. #40571
Ensure that post thumbnail is cached in latest post block. #40571
Conversation
@spacedmonkey I've reached out to a few folks to see if we can get a review from a PHP-focused dev on this. |
Co-authored-by: Tonya Mork <[email protected]>
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 👍
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.
@spacedmonkey Awesome work! Can you add a unit test, specifically around the cache bit for featured images? To ensure no additional request per featured image is fired.
@felixarntz I would love to, but I don't where I would do this. That test should really live in core. Do you have any recommendation on how I would add a test here. |
I think it would still work within Gutenberg's codebase, no? I think if we don't add tests here, we probably won't later add them to core either, since Gutenberg largely just gets merged into core over time. You could add a file |
I agree with @felixarntz. The PHPUnit tests are also backported to Core along with the source code changes. But if there are no tests, then none are added to Core, meaning changes are backported without tests being added. Creating them now not only validates them during the R&D, stabilization, and maturity process in Gutenberg, but also ensures there are tests to backport once it lands in Core. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
@felixarntz @hellofromtonya Point taken, unit tests added. Worth noting, I don't like query counting tests, so I found another way of testing this. |
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.
A couple of notes in the tests.
It's a shame update_post_thumbnail_cache()
requires a switch to WP_Query
but I understand what's happening.
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 have a few remarks about the test.
Thank you.
Co-authored-by: Anton Vlasenko <[email protected]>
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.
I cherry-picked this to wp/6.0 branch to be included in WordPress 6.0 RC2 later today a2be55c |
* Ensure tht post thumbnail is cached in latest post block. * Safe gaurd. Co-authored-by: Tonya Mork <[email protected]> * Add unit tests. * Improve test. * Apply suggestions from code review Co-authored-by: Peter Wilson <[email protected]> * Feedback. * Improve unit tests. * Update phpunit/blocks/render-last-posts-test.php Co-authored-by: Anton Vlasenko <[email protected]> * Change variable name. * Remove message. Co-authored-by: Tonya Mork <[email protected]> Co-authored-by: Peter Wilson <[email protected]> Co-authored-by: Anton Vlasenko <[email protected]>
We will have to bring unit tests to WordPress core in a dedicated patch. |
What?
Ensure that post thumbnails are correctly primed when using the last post block.
Why?
If this function is not called, it results in one query to post meta table. Calling
update_post_thumbnail_cache
primes all caches in one.How?
Testing Instructions
Screenshots or screencast