-
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
Improve performance of wp_navigation lookup. #36891
Conversation
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.
My implementation PR originally did something similar to what you are doing here but I got the inverse feedback from @noisysocks.
I now don't know which version is safest and fastest.
In reviewing this PR I'd say it's going to be safe as it's limited to 20
posts. We might argue that this limit might mean that there's a chance no posts with blocks will be found in the set but that's highly unlikely.
Thank you for reminding me about
- Preferring
WP_Query
no_found_rows
- 👍
I'll defer to others for a final 👍 as PHP is not my forte but this seems like a nice improvement.
From what I can see, your original implementation was on the money. The LIKE search, is EXTREMELY expensive from a database standard point. I have worked on sites with 500k+ articles and this search would have take over 15 seconds to return. A search like this in core should be avoided at all costs, as LIKE searches like will not scale. |
@spacedmonkey I'm all for using WP_Query 💯 . About the |
@adamziel Here is some profile information. With like search 0.0766Returning 20 items. 0.0432 |
@spacedmonkey this is profile for just the query using double
|
@adamziel This isn't really about PHP performance, is about MySQL performance, which I have shown here to be much better. Having working on large WordPress sites for years, I know for a fact, that WordPress searches, could make databases hangs adds more processing on database servers. This compare in php is extremely cheap and almost not worth profiling. |
@spacedmonkey still, I believe that switching to |
More data as promised:
To measure the speed of different ways of filtering, I did a benchmark with All
|
'order' => 'ASC', | ||
'orderby' => 'name', | ||
'post_status' => 'publish', | ||
'posts_per_page' => 20, // Try the first 20 posts. |
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.
Would be nice to filter by post_content != ''
. Is there a need to fetch more than 1? Do we ever expect to see a non-empty wp_navigation post that has no blocks in it? CC @getdave @noisysocks
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.
We don't expect it but I guess it could happen...
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.
* Use WP_Query * Only published posts. * Fix lint error
Description
Improve the performance of the lookup for wp_navigation posts. This improves performance in a number of way.
no_found_rows
, as we don't care about the number of posts here.WP_Query
instead ofget_posts
should be avoided at all costs, as it is unfilterable / uncachable.has_blocks
in php, as this check is cheap.How has this been tested?
Screenshots
Types of changes
Checklist:
*.native.js
files for terms that need renaming or removal).