Inefficient database queries
-
This is similar to this issue.
There are two inefficient queries that are run by this plugin every night at midnight. You can see these queries in the
wpp_cache_maintenance()
function:function wpp_cache_maintenance() {
global $wpdb;// delete posts that have not been seen in the past 30 days
$wpdb->query( “DELETE FROM “.$wpdb->prefix.”popularpostsdatacache WHERE day < DATE_SUB(‘”.$this->curdate().”‘, INTERVAL 30 DAY);” );// delete posts that have been deleted or trashed – added on ver 2.3.3
$wpdb->query( “DELETE FROM {$wpdb->prefix}popularpostsdata WHERE postid IN (SELECT c.id FROM (SELECT id FROM {$wpdb->prefix}popularpostsdatacache GROUP BY id) c LEFT JOIN {$wpdb->posts} p ON c.id = p.ID WHERE p.ID IS NULL OR p.post_status = ‘trash’);” );
$wpdb->query( “DELETE FROM {$wpdb->prefix}popularpostsdatacache WHERE id IN (SELECT c.id FROM (SELECT id FROM {$wpdb->prefix}popularpostsdatacache GROUP BY id) c LEFT JOIN {$wpdb->posts} p ON c.id = p.ID WHERE p.ID IS NULL OR p.post_status = ‘trash’);” );}
The queries are found after the
//delete posts that have been deleted or trashed
section. The first query took over 22 seconds to modify zero rows, and the second query took over 475 seconds to modify zero rows! That’s only 5 seconds short of 8 minutes!These inefficient queries can cause a site to go down when the cron job is run, and should be made to run much more quickly.
https://www.ads-software.com/plugins/wordpress-popular-posts/
- The topic ‘Inefficient database queries’ is closed to new replies.