Merge pull request #19225 from roylindauer/17355-SplitAndFilter

Split layered nav transient per issue #17355
This commit is contained in:
Mike Jolley 2018-03-14 12:50:54 +00:00 committed by GitHub
commit 06418f67e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -700,6 +700,8 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
foreach ( $attributes as $attribute_key => $attribute ) {
$value = '';
delete_transient( 'wc_layered_nav_counts_' . $attribute_key );
if ( is_null( $attribute ) ) {
if ( taxonomy_exists( $attribute_key ) ) {
// Handle attributes that have been unset.
@ -725,7 +727,6 @@ class WC_Product_Data_Store_CPT extends WC_Data_Store_WP implements WC_Object_Da
}
}
update_post_meta( $product->get_id(), '_product_attributes', $meta_values );
delete_transient( 'wc_layered_nav_counts' );
}
}

View File

@ -369,13 +369,22 @@ class WC_Widget_Layered_Nav extends WC_Widget {
// We have a query - let's see if cached results of this query already exist.
$query_hash = md5( $query );
$cached_counts = (array) get_transient( 'wc_layered_nav_counts' );
// Maybe store a transient of the count values.
$cache = apply_filters( 'woocommerce_layered_nav_count_maybe_cache', true );
if ( true === $cache ) {
$cached_counts = (array) get_transient( 'wc_layered_nav_counts_' . $taxonomy );
} else {
$cached_counts = array();
}
if ( ! isset( $cached_counts[ $query_hash ] ) ) {
$results = $wpdb->get_results( $query, ARRAY_A ); // @codingStandardsIgnoreLine
$counts = array_map( 'absint', wp_list_pluck( $results, 'term_count', 'term_count_id' ) );
$cached_counts[ $query_hash ] = $counts;
set_transient( 'wc_layered_nav_counts', $cached_counts, DAY_IN_SECONDS );
if ( true === $cache ) {
set_transient( 'wc_layered_nav_counts_' . $taxonomy, $cached_counts, DAY_IN_SECONDS );
}
}
return array_map( 'absint', (array) $cached_counts[ $query_hash ] );