Revisions: Skip rendered fields in REST API responses#76347
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What?
Optimizes the revisions REST API endpoint and client-side queries to avoid fetching expensive rendered fields (
content.rendered,title.rendered,excerpt.rendered) when only raw data is needed.Why?
The speedup is significant: from 5-6 seconds to 50-60 ms for 20 revisions!
The REST API
_fieldsdocumentation states that nested fields are supported using dot notation. However, the coreWP_REST_Revisions_Controllerusesin_array()which doesn't match nested keys likecontent.raw— so clients either get bothrawandrendered, or neither.Several other controllers already use
rest_is_field_included()forraw/renderedsub-fields:WP_REST_Posts_ControllerWP_REST_Templates_ControllerWP_REST_Menu_Items_ControllerWP_REST_Global_Styles_ControllerWP_REST_Themes_ControllerHow?
PHP: Override revisions controller (WordPress 7.0 compat)
Gutenberg_REST_Revisions_ControllerextendingWP_REST_Revisions_Controllerin_array()checks withrest_is_field_included()forcontent,title,excerpt, andguidfieldsregister_post_type_argsfilter, following the same pattern as the autosaves controller overrideJS: Request only needed sub-fields
getCurrentRevision,getPreviousRevision, the revisions slider,useEntityProp, andrestoreRevisionto use_fields=id,date,author,meta,title.raw,excerpt.raw,content.rawTesting Instructions
_fields=id%2Cdate%2Cauthor%2Cmeta%2Ctitle.raw%2Cexcerpt.raw%2Ccontent.rawcontent.rawbut NOTcontent.renderedTesting Instructions for Keyboard