From d1dbe4492e9f3ed9c34510053064e2331cfb8fbb Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 3 Jul 2014 12:01:51 +0100 Subject: [PATCH] Clear comment transients only on wp_update_comment_count Does not need to be flushed when editing a product. Part of #5777 --- includes/class-wc-comments.php | 19 ++++++------------- includes/class-wc-install.php | 3 --- includes/wc-product-functions.php | 4 +--- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/includes/class-wc-comments.php b/includes/class-wc-comments.php index b67ccdc9703..f7573a1796c 100644 --- a/includes/class-wc-comments.php +++ b/includes/class-wc-comments.php @@ -26,8 +26,7 @@ class WC_Comments { add_action( 'comment_post', array( __CLASS__, 'add_comment_rating' ), 1 ); // clear transients - add_action( 'wp_set_comment_status', array( __CLASS__, 'clear_transients' ) ); - add_action( 'edit_comment', array( __CLASS__, 'clear_transients' ) ); + add_action( 'wp_update_comment_count', array( __CLASS__, 'clear_transients' ) ); // Secure order notes add_filter( 'comments_clauses', array( __CLASS__, 'exclude_order_comments' ), 10, 1 ); @@ -121,13 +120,11 @@ class WC_Comments { */ public static function add_comment_rating( $comment_id ) { if ( isset( $_POST['rating'] ) ) { - - if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) + if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) { return; + } add_comment_meta( $comment_id, 'rating', (int) esc_attr( $_POST['rating'] ), true ); - - self::clear_transients( $comment_id ); } } @@ -136,13 +133,9 @@ class WC_Comments { * * @param mixed $comment_id */ - public static function clear_transients( $comment_id ) { - $comment = get_comment( $comment_id ); - - if ( ! empty( $comment->comment_post_ID ) ) { - delete_transient( 'wc_average_rating_' . absint( $comment->comment_post_ID ) ); - delete_transient( 'wc_rating_count_' . absint( $comment->comment_post_ID ) ); - } + public static function clear_transients( $post_id ) { + delete_transient( 'wc_average_rating_' . absint( $post_id ) ); + delete_transient( 'wc_rating_count_' . absint( $post_id ) ); } } diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index d13cb5c6c40..62e8a4aa6cc 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -108,9 +108,6 @@ class WC_Install { $this->create_files(); $this->create_css_from_less(); - // Clear transient cache - wc_delete_product_transients(); - // Queue upgrades $current_version = get_option( 'woocommerce_version', null ); $current_db_version = get_option( 'woocommerce_db_version', null ); diff --git a/includes/wc-product-functions.php b/includes/wc-product-functions.php index 15932d82b8c..33c390379ba 100644 --- a/includes/wc-product-functions.php +++ b/includes/wc-product-functions.php @@ -92,9 +92,7 @@ function wc_delete_product_transients( $post_id = 0 ) { // Clear product specific transients $post_transient_names = array( 'wc_product_children_ids_', - 'wc_product_total_stock_', - 'wc_average_rating_', - 'wc_rating_count_' + 'wc_product_total_stock_' ); if ( $post_id > 0 ) {