Skip to content

Instantly share code, notes, and snippets.

@jmslbam
Last active February 10, 2017 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmslbam/5e3a79b32af14bad05374e9791604e01 to your computer and use it in GitHub Desktop.
Save jmslbam/5e3a79b32af14bad05374e9791604e01 to your computer and use it in GitHub Desktop.
WPCOM_VIP_CLI_Command
<?php
class WPCOM_VIP_CLI_Command extends WP_CLI_Command {
/**
* Clear all of the caches for memory management
*/
protected function stop_the_insanity() {
/**
* @var \WP_Object_Cache $wp_object_cache
* @var \wpdb $wpdb
*/
global $wpdb, $wp_object_cache;
$wpdb->queries = array(); // or define( 'WP_IMPORTING', true );
if ( is_object( $wp_object_cache ) ) {
$wp_object_cache->group_ops = array();
$wp_object_cache->stats = array();
$wp_object_cache->memcache_debug = array();
$wp_object_cache->cache = array();
if ( method_exists( $wp_object_cache, '__remoteset' ) ) {
$wp_object_cache->__remoteset(); // important
}
}
}
/**
* Disable term counting so that terms are not all recounted after every term operation
*/
protected function start_bulk_operation(){
// Disable term count updates for speed
wp_defer_term_counting( true );
// Term count was still being call on wp_post_insert via this action.
remove_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10);
}
/**
* Re-enable Term counting and trigger a term counting operation to update all term counts
*/
protected function end_bulk_operation(){
wp_defer_term_counting( false ); // This will also trigger a term count.
// add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment