Plugin Directory

Changeset 3847213


Ignore:
Timestamp:
12/06/2026 05:45:22 AM (less than one hour ago)
Author:
brokensmile.2103
Message:

Release v2.0.8 - First view after reset no longer clears the site-wide query cache

Location:
init-view-count
Files:
51 added
4 edited

Legend:

Unmodified
Added
Removed
  • init-view-count/trunk/includes/reset-schedule.php

    r3801436 r3847213  
    232232        init_plugin_suite_view_count_flush_meta_cache_many( $touched );
    233233
     234        // v2.0.8: thứ hạng theo ngày / tuần / tháng vừa đổi → làm mới cache WP_Query đúng 1 lần (trước
     235        // đây việc này xảy ra ngẫu nhiên hàng nghìn lần qua add_post_meta() ở lượt xem đầu mỗi bài).
     236        if ( ! empty( $touched ) && function_exists( 'wp_cache_set_posts_last_changed' ) ) {
     237                wp_cache_set_posts_last_changed();
     238        }
     239
    234240        $summary = array(
    235241                'total_posts'    => count( $posts ),
  • init-view-count/trunk/includes/utils.php

    r3801436 r3847213  
    149149        $locked = 1 === (int) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, %d)', $lock_name, 3 ) );
    150150
    151         // $unique = true để tránh insert trùng nếu có request khác vừa insert xong.
    152         if ( false === add_post_meta( $post_id, $meta_key, $offset, true ) ) {
     151        // v2.0.8: tạo row bằng SQL trực tiếp thay cho add_post_meta(). add_post_meta() chạy hook
     152        // added_post_meta → WordPress 6.3+ đổi mốc "posts last_changed" → mọi cache WP_Query /
     153        // get_posts của CẢ SITE (Redis / Memcached) bị vô hiệu. Sau mỗi lần reset ngày / tuần / tháng,
     154        // lượt xem đầu tiên của TỪNG bài đi vào nhánh này → hàng nghìn lần xoá cache mỗi ngày trên
     155        // site lớn. Vẫn kiểm tra "đã có row chưa" trong khoá như trước (không tạo trùng).
     156        // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Kiểm tra trực tiếp DB trong khoá, không được dùng cache.
     157        $exists = (bool) $wpdb->get_var(
     158                $wpdb->prepare(
     159                        "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s LIMIT 1",
     160                        $post_id,
     161                        $meta_key
     162                )
     163        );
     164
     165        $inserted = false;
     166        if ( ! $exists ) {
     167                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- Ghi trực tiếp có chủ đích (xem trên).
     168                $inserted = false !== $wpdb->insert(
     169                        $wpdb->postmeta,
     170                        array(
     171                                'post_id'    => $post_id,
     172                                'meta_key'   => $meta_key, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
     173                                'meta_value' => (string) $offset, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
     174                        ),
     175                        array( '%d', '%s', '%s' )
     176                );
     177        }
     178
     179        if ( ! $inserted ) {
    153180                // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Xem giải thích ở init_plugin_suite_view_count_atomic_increment().
    154181                $wpdb->query(
    … …  
    166193                $wpdb->query( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $lock_name ) );
    167194        }
     195
     196        // Ghi bằng SQL → tự xoá cache post meta của bài (add_post_meta() trước đây tự làm việc này).
     197        wp_cache_delete( $post_id, 'post_meta' );
    168198}
    169199
  • init-view-count/trunk/init-view-count.php

    r3801466 r3847213  
    44 * Description: Lightweight plugin to track real post views with scroll & delay detection, smart ranking, and flexible shortcodes.
    55 * Plugin URI: https://inithtml.com/plugin/init-view-count/
    6  * Version: 2.0.7
     6 * Version: 2.0.8
    77 * Author: Init HTML
    88 * Author URI: https://inithtml.com/
    … …  
    1818
    1919// === Constants ===
    20 define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_VERSION', '2.0.7' );
     20define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_VERSION', '2.0.8' );
    2121define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_SLUG', 'init-view-count' );
    2222define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_DIR', plugin_dir_path( __FILE__ ) );
  • init-view-count/trunk/readme.txt

    r3817525 r3847213  
    55Tested up to: 7.2
    66Requires PHP: 7.4
    7 Stable tag: 2.0.7
     7Stable tag: 2.0.8
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    389389== Changelog ==
    390390
     391= 2.0.8 – December 6, 2026 =
     392- Improvement: the first view of a post after a daily, weekly or monthly reset no longer clears the site-wide query cache (WordPress 6.3+ with Redis or Memcached)
     393- Improvement: new counter rows are created directly in the database instead of through `add_post_meta()`, which invalidated every cached `WP_Query` / `get_posts` result once per post
     394- Improvement: the query cache is now refreshed exactly once after each reset, so day / week / month rankings stay up to date
     395
    391396= 2.0.7 – November 14, 2026 =
    392397- Fix: when the scroll area (or the whole page) fit on screen at first load – images not loaded yet, content still a loading placeholder or inserted later – the scroll check passed immediately, so a view counted after the delay without any scrolling. This case now only counts once the page has finished loading and the layout has been stable for 1 second, and it is checked again right before sending, so content that grows in the meantime requires real scrolling
Note: See TracChangeset for help on using the changeset viewer.