Skip to content

Commit

Permalink
add wp_suspend_cache_addition() to bulk operation calls
Browse files Browse the repository at this point in the history
Add a call to https://developer.wordpress.org/reference/functions/wp_suspend_cache_addition/ as part of the start bulk operations to disable adding items to the object cache.
It then re-enables adding items to the object cache in end_bulk_operation().
  • Loading branch information
sboisvert authored Mar 21, 2024
1 parent 90bd992 commit 3eb2484
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vip-helpers/vip-wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@ public static function vip_inmemory_cleanup() {

/**
* Disable term counting so that terms are not all recounted after every term operation
* Disable adding data to the object cache
*/
public static function start_bulk_operation() {
// Disable term count updates for speed
wp_defer_term_counting( true );
//disable adding data to object cache (in-memory and memcache/redis)
wp_suspend_cache_addition( true );
}

/**
* Re-enable Term counting and trigger a term counting operation to update all term counts
* Re-enable adding data to the object cache
*/
public static function end_bulk_operation() {
// This will also trigger a term count.
wp_defer_term_counting( false );
//re-enable adding data to object cache (in-memory and memcache/redis)
wp_suspend_cache_addition( false );
}
}

1 comment on commit 3eb2484

@sboisvert
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better description:

Add a call to wp_suspend_cache_addition as part of the start bulk operations to disable adding items to the object cache. It then re-enables adding items to the object cache in end_bulk_operation().
This should improve performance during import style operations by stopping WP from adding things to the object cache (both local and remote).

Please sign in to comment.