-
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 post template block. #40572
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since a Query Loop block might not contain the
Post Featured Image
block, wouldn't this result in extra db queries in that case? Can we incorporate this in the Post Featured Image block somehow and have some performance improvements?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.
Fair point. I have moved the logic to the feature image block.
I tried to get the query as part of context, why I am not sure if this is even possible. My worry is the the feature image is used in a query block or other place, where the query is different than the main query on the page.
Any ideas @ntsekouras
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.
👋 Post Featured Image knows if is in a Query Loop if the
queryId
prop is filled from its context. An example would be here, but we would need to check forqueryId
. Noting that the queryId could be zero.I'm not really familiar with this optimization, but would it make sense in the block itself or is it more about passing a query?
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 function
update_post_thumbnail_cache
accepts the query object as a param. When it does, all thumbnail caches are primed in one request. It uses the WP_Query object to get the posts and then loop the thumbnails.I think we should pass the query in here, as a feature image block could be used in different query loops.
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 took a closer look here and I think this could work well in Post Template block.
Can you think of any implications with this code @gziolo?
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.
@ntsekouras, that would be similar to what @spacedmonkey proposes in #40752 for the Navigation block.
Anyway, it largely depends on whether the Post Featured Image is the immediate child in the Post Template or it can be included at any level of nesting. I'm not sure whether
$block->parsed_block['innerBlocks']
is a flat list of inner blocks, but it would have to be further investigated if you plan to go this route.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.
Oh.. that's true. It would make sense to have some metrics about this optimization whether it's better to recurse through innerBlocks to find if featured image exists in comparison to the two requests.
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.
It would not be 2 requests, if you have 10 feature images on a page, it this could result in 10 times 2 ( one for post one for meta ) for each thumbnail. I have code in here to recursively loop through blocks to find nested navigation link blocks. I can confirm, that the inner is, is not a full list. The inner block, have inner blocks. So you have to recursively loop through blocks. It is a pain, but I have hidden the logic, so we could adapt it here.
The check here would be much simpler, as we just been a boolean of has feature image block.
@ntsekouras @gziolo Should I move the logic back to the post template block with a recursively lookup for featured-image blocks?
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.
It is also worthing noting, I dont have an issue with having this function in both the feature image and post template block. I don't think it hurts having it in both places.
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.
Yes, I think it's better to be there and pass the specific query. Also without some metrics I'm not even sure if it worths it to recurse through innerBlocks or just call the function 😄