Closed davidsword closed 3 years ago
Seems https://github.com/Automattic/msm-sitemap/issues/112 would be a much better approach to eliminate this query all together.
Instead of looking for posts based on the last modified date, it might make sense to hook into transition post status instead and track the dates for those posts (in an option) and then use those instead.
Closing this issue out in favour for #112
Hello
This query has been appearing in slow query logs on busier multisites.
https://github.com/Automattic/msm-sitemap/blob/6d58e2e65d77f140fe1e32fde7ee4ef48a01add4/msm-sitemap.php#L590
Though it's running on cron having dozens or hundreds of sites running this can be overly taxing.
Some organizations may not be editing posts from months past, and may benefit more from the option of using a more efficient query. For this example case, here's an EXPLAIN on that query:
Adding
AND post_status = 'publish' AND post_date > DATE_FORMAT(NOW() - INTERVAL 1 MONTH, '%Y-%m-%d %H:%i:%s')
to the query resulted in this case 355,278 less rows scanned, which is a significant performance bump:Noting
post_status
was added to properly leverage the date intype_status_date
. Both of these args would great candidates for filters to help provide some options to improve this query when it performs poorly for some sites.