Skip to content

Instantly share code, notes, and snippets.

@cfg
Created December 3, 2015 16:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cfg/2181d8d2807afed583b0 to your computer and use it in GitHub Desktop.
Save cfg/2181d8d2807afed583b0 to your computer and use it in GitHub Desktop.
Fix expensive comment queries
<?php
if ( defined( 'WPCOM_IS_VIP_ENV' ) && true === WPCOM_IS_VIP_ENV ) {
wpcom_vip_load_plugin( 'disable-comments-query' );
// Kill wp_count_comments lookups because they happen too frequently and are super slow.
if ( is_admin() ) {
add_filter( 'wp_count_comments', function( $counts, $post_id ) {
if ( $post_id )
return $counts;
return (object) array(
'approved' => 0,
'spam' => 0,
'trash' => 0,
'total_comments' => 0,
'moderated' => 0,
'post-trashed' => 0,
);
}, 10, 2 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment