Skip to content

Commit 66a3959

Browse files
committed
free up memory.
1 parent 621ac33 commit 66a3959

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

php/class-cli.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function sync( $args, $assoc_args ) {
106106
$this->do_process( $query, 'sync' );
107107
if ( ! $query->have_posts() ) {
108108
\WP_CLI::log( \WP_CLI::colorize( '%gAll assets synced.%n' ) );
109+
delete_option( '_cld_cli_analyzed' );
109110
}
110111

111112
}
@@ -161,9 +162,7 @@ protected function do_process( &$query, $process ) {
161162
$this->{$process}( $posts, $total );
162163

163164
// Free up memory.
164-
if ( method_exists( $this, 'stop_the_insanity' ) ) {
165-
$this->stop_the_insanity();
166-
}
165+
$this->oh_the_humanity();
167166

168167
// Paginate.
169168
$query_args = $query->query_vars;
@@ -286,4 +285,25 @@ protected static function pad_name( $name, $max_length, $pad_char = '.', $concat
286285

287286
return $out;
288287
}
288+
289+
/**
290+
* Workaround to prevent memory leaks from growing variables
291+
*/
292+
protected function oh_the_humanity() {
293+
global $wpdb, $wp_object_cache;
294+
if ( method_exists( $this, 'stop_the_insanity' ) ) {
295+
return $this->stop_the_insanity();
296+
}
297+
298+
$wpdb->queries = array();
299+
if ( is_object( $wp_object_cache ) ) {
300+
$wp_object_cache->group_ops = array();
301+
$wp_object_cache->stats = array();
302+
$wp_object_cache->memcache_debug = array();
303+
$wp_object_cache->cache = array();
304+
if ( method_exists( $wp_object_cache, '__remoteset' ) ) {
305+
$wp_object_cache->__remoteset();
306+
}
307+
}
308+
}
289309
}

0 commit comments

Comments
 (0)