Avoid query if no limit is set.

This commit is contained in:
Mike Jolley 2018-05-01 13:26:57 +01:00
parent 18a8a6b752
commit 461dfd6489
1 changed files with 7 additions and 2 deletions

View File

@ -157,11 +157,16 @@ class WC_Cache_Helper {
if ( ! wp_using_ext_object_cache() && ! empty( $version ) ) {
global $wpdb;
$limit = apply_filters( 'woocommerce_delete_version_transients_limit', 1000 );
$limit = apply_filters( 'woocommerce_delete_version_transients_limit', 1000 );
if ( ! $limit ) {
return;
}
$affected = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s ORDER BY option_id LIMIT %d;", '\_transient\_%' . $version, $limit ) ); // WPCS: cache ok, db call ok.
// If affected rows is equal to limit, there are more rows to delete. Delete in 10 secs.
if ( $affected === $limit && 0 !== $limit ) {
if ( $affected === $limit ) {
wp_schedule_single_event( time() + 10, 'delete_version_transients', array( $version ) );
}
}