-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Improve performance of wp_navigation lookup. #36891
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,17 +145,23 @@ function block_core_navigation_get_first_non_empty_navigation() { | |
| // see: | ||
| // - https://github.com/WordPress/wordpress-develop/blob/ba943e113d3b31b121f77a2d30aebe14b047c69d/src/wp-includes/nav-menu.php#L613-L619. | ||
| // - https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters. | ||
| $navigation_posts = get_posts( | ||
| array( | ||
| 'post_type' => 'wp_navigation', | ||
| 'order' => 'ASC', | ||
| 'orderby' => 'name', | ||
| 'posts_per_page' => 1, // only the first post. | ||
| 's' => '<!-- wp:', // look for block indicators to ensure we only include non-empty Navigations. | ||
| ) | ||
| $parsed_args = array( | ||
| 'post_type' => 'wp_navigation', | ||
| 'no_found_rows' => true, | ||
| 'order' => 'ASC', | ||
| 'orderby' => 'name', | ||
| 'post_status' => 'publish', | ||
| 'posts_per_page' => 20, // Try the first 20 posts. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to filter by
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't expect it but I guess it could happen...
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ); | ||
| return count( $navigation_posts ) ? $navigation_posts[0] : null; | ||
|
|
||
| $navigation_posts = new WP_Query( $parsed_args ); | ||
| foreach ( $navigation_posts->posts as $navigation_post ) { | ||
| if ( has_blocks( $navigation_post ) ) { | ||
| return $navigation_post; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.