From f5d95392d21269f5d173287a6707e48a5b530f37 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Mon, 21 Aug 2023 00:13:50 +0200 Subject: [PATCH] Improve story comment count refresh Do not update the meta and purge the cache if nothing changed! --- includes/functions/_utility.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index b87b70b8..58f75707 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -241,11 +241,16 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { */ + $comment_count_changed = $comment_count != absint( $old_data['comment_count'] ); $old_data['comment_count'] = $comment_count; $old_data['comment_count_timestamp'] = time(); // Update meta - if ( FICTIONEER_STORY_COMMENT_COUNT_TIMEOUT > 0 && ! ( $args['force_comment_count_refresh'] ?? 0 ) ) { + if ( + $comment_count_changed && + FICTIONEER_STORY_COMMENT_COUNT_TIMEOUT > 0 && + ! ( $args['force_comment_count_refresh'] ?? 0 ) + ) { update_post_meta( $story_id, 'fictioneer_story_data_collection', $old_data ); fictioneer_purge_post_cache( $story_id ); }