Performance of get_total_unindexed Query
travisanderson99 opened this issue · comments
- I've read and understood the contribution guidelines.
- I've searched for any related issues and avoided creating a duplicate issue.
Please give us a description of what happened
When visiting /wp-admin on our site, this query is taking roughly 12 seconds to execute on our sites:
Yoast\WP\SEO\Actions\Indexing\Abstract_Indexing_Action->get_total_unindexed
SELECT COUNT(P.ID)
FROM wp_2_posts AS P
LEFT JOIN wp_2_yoast_indexable AS I
ON P.ID = I.object_id
AND I.link_count IS NOT NULL
AND I.object_type = 'post'
LEFT JOIN wp_2_yoast_seo_links AS L
ON L.post_id = P.ID
AND L.target_indexable_id IS NULL
AND L.type = 'internal'
AND L.target_post_id IS NOT NULL
AND L.target_post_id != 0
WHERE ( I.object_id IS NULL
OR L.post_id IS NOT NULL )
AND P.post_status = 'publish'
AND P.post_type IN ('post', 'page', 'players', 'archived-players', 'colleges', 'products', 'graphics', 'partners', 'programs', 'blogs', 'high_schools', 'games', 'auto_articles')
We do have a very large wp_2_posts table (slightly over 1 million entries) which is likely a factor in the query time.
To Reproduce
Step-by-step reproduction instructions
- Visit /wp-admin on a site with Yoast installed with a very large wp_posts table, ideally hundreds of thousands of posts.
- Investigate the response time for the following query:
Yoast\WP\SEO\Actions\Indexing\Abstract_Indexing_Action->get_total_unindexed
Screenshots, screen recording, code snippet
If possible, please provide a screenshot, a screen recording or a code snippet which demonstrates the bug.
A screenshot from the Query Monitor plugin:
Technical info
- If relevant, which editor is affected (or editors):
- Block Editor
- Gutenberg Editor
- Elementor Editor
- Classic Editor
- [ x] Other: Main admin dashboard
- Which browser is affected (or browsers):
- [x ] Chrome
- [x ] Firefox
- [x ] Safari
- Other:
Used versions
-
Device you are using:
-
Operating system:
-
PHP version: 8.2
-
WordPress version: Latest (6.7)
-
WordPress Theme: Custom
-
Yoast SEO version: 23.7
-
Relevant plugins in case of a bug:
Thanks for using the Yoast SEO plugin and for reporting this issue.
While the query is aggressively cached to minimize its occurrence, it may take longer to process on slower sites. If your SEO optimization is complete (Yoast SEO > Tools), you might consider adding the following filter to your site:
add_filter( 'Yoast\WP\SEO\enable_cron_indexing', '__return_false' );
This will reduce the frequency of this query running, especially on the initial wp-admin
page load, which might be the main source of the issue.
In case the SEO Data Optimization process is not yet completed on your website (Yoast SEO > Tools), we recommend you update the Yoast SEO plugin to 24.0 and run it before to check whether any improvements happen.
We hope this helps! Feel free to let us know if you need any more help.