#55620 closed enhancement (fixed)
Prime caches linked objects in menu item REST API
Reported by: | spacedmonkey | Owned by: | spacedmonkey |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | REST API | Keywords: | has-patch needs-unit-tests has-dev-note |
Focuses: | rest-api, performance | Cc: |
Description
Follow on from [52975].
Ensure that all the linked objects, such as terms and posts that are linked to a menu item, are primed in cache, in the menu item controller.
This will result in far less database queries per page.
Attachments (2)
Change History (38)
This ticket was mentioned in PR #2631 on WordPress/wordpress-develop by spacedmonkey.
2 years ago
#1
- Keywords has-patch added; needs-patch removed
#5
@
2 years ago
I have put together a very simple patch, that needs to work results are promising. See the before and after screenshots. Before 31 queries vs after 19.
This ticket was mentioned in Slack in #hosting-community by javier. View the logs.
2 years ago
This ticket was mentioned in Slack in #hosting-community by javier. View the logs.
2 years ago
This ticket was mentioned in Slack in #hosting-community by jadonn. View the logs.
2 years ago
This ticket was mentioned in Slack in #hosting-community by javier. View the logs.
2 years ago
This ticket was mentioned in Slack in #hosting-community by jadonn. View the logs.
2 years ago
TimothyBJacobs commented on PR #2631:
2 years ago
#11
I wonder if it would make sense to add this as a flag in WP_Query
itself instead of filtering in like this. For instance update_menu_item_object_cache
that would automatically call this new helper function when set. I think that would clean up the controller code a bit and make it more obvious to 3rd party developers that this is a performance option they have available to them.
spacedmonkey commented on PR #2631:
2 years ago
#12
I wonder if it would make sense to add this as a flag in WP_Query itself instead of filtering in like this. For instance update_menu_item_object_cache that would automatically call this new helper function when set. I think that would clean up the controller code a bit and make it more obvious to 3rd party developers that this is a performance option they have available to them.
That does sound interesting, I really do not want more code in WP_Query. That class is really too long and has too many params.
Another idea I had, was moving the query logic to another method in Post Controller and the overriding that. What do we think of that idea.
Like
protected function get_objects( $args ) { $query = new WP_Query( $args ); .... }
spacedmonkey commented on PR #2631:
2 years ago
#13
@TimothyBJacobs I have actioned your feedback. I think the result is cleaner. Can you take a look.
TimothyBJacobs commented on PR #2631:
2 years ago
#14
This looks great to me @spacedmonkey! We just need to make sure to add a changelog entry for the new parameter.
This ticket was mentioned in PR #2806 on WordPress/wordpress-develop by spacedmonkey.
2 years ago
#15
Trac ticket: https://core.trac.wordpress.org/ticket/55620
spacedmonkey commented on PR #2631:
2 years ago
#16
@manuelRod @TimothyBJacobs I have come up another lighter weight version of this PR. See what you think - https://github.com/WordPress/wordpress-develop/pull/2806/
TimothyBJacobs commented on PR #2631:
2 years ago
#17
Personally I prefer it as a WP_Query
option like you have here, but I think either are workable. Though it is a bit odd to have menu item specific code inside of the base posts controller.
spacedmonkey commented on PR #2631:
2 years ago
#19
#22
@
2 years ago
- Keywords needs-dev-note added
There are a lot of caching related changes in 6.1 and a dev note should be written collecting them all. Marking this for inclusion.
This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.
2 years ago
This ticket was mentioned in PR #3403 on WordPress/wordpress-develop by spacedmonkey.
2 years ago
#27
Trac ticket: https://core.trac.wordpress.org/ticket/55620
Move menu item priming to after meta is primed.
#28
@
2 years ago
Reopenning as seen an issue. Priming of menu item linked objects after menu item post meta is primed. See #3403.
CC @peterwilsoncc @mukesh27
peterwilsoncc commented on PR #3403:
2 years ago
#29
Am I correct in thinking the issue is the meta cache needs to be primed to reduce the queries from these two lines?
A unit test or two would be dandy to make sure the code isn't later refactored to prime the menus prior to the meta data.
spacedmonkey commented on PR #3403:
2 years ago
#30
A unit test or two would be dandy to make sure the code isn't later refactored to prime the menus prior to the meta data.
Unit tests added.
spacedmonkey commented on PR #3403:
2 years ago
#31
@peterwilsoncc Good call out. I have improves the tests.
Trac ticket: https://core.trac.wordpress.org/ticket/55620