Changeset 3847213
- Timestamp:
- 12/06/2026 05:45:22 AM (less than one hour ago)
- Location:
- init-view-count
- Files:
-
- 51 added
- 4 edited
-
tags/2.0.8 (added)
-
tags/2.0.8/assets (added)
-
tags/2.0.8/assets/css (added)
-
tags/2.0.8/assets/css/admin-style.css (added)
-
tags/2.0.8/assets/css/style.css (added)
-
tags/2.0.8/assets/img (added)
-
tags/2.0.8/assets/img/thumbnail.svg (added)
-
tags/2.0.8/assets/js (added)
-
tags/2.0.8/assets/js/blocks-editor.js (added)
-
tags/2.0.8/assets/js/init-shortcode-builder.js (added)
-
tags/2.0.8/assets/js/ranking.js (added)
-
tags/2.0.8/assets/js/script.js (added)
-
tags/2.0.8/assets/js/shortcodes.js (added)
-
tags/2.0.8/blocks (added)
-
tags/2.0.8/blocks/view-count (added)
-
tags/2.0.8/blocks/view-count/block.json (added)
-
tags/2.0.8/blocks/view-count/render.php (added)
-
tags/2.0.8/blocks/view-list (added)
-
tags/2.0.8/blocks/view-list/block.json (added)
-
tags/2.0.8/blocks/view-list/render.php (added)
-
tags/2.0.8/blocks/view-ranking (added)
-
tags/2.0.8/blocks/view-ranking/block.json (added)
-
tags/2.0.8/blocks/view-ranking/render.php (added)
-
tags/2.0.8/includes (added)
-
tags/2.0.8/includes/abilities-api.php (added)
-
tags/2.0.8/includes/blocks.php (added)
-
tags/2.0.8/includes/dashboard-widget.php (added)
-
tags/2.0.8/includes/hooks.php (added)
-
tags/2.0.8/includes/reset-schedule.php (added)
-
tags/2.0.8/includes/rest-api.php (added)
-
tags/2.0.8/includes/settings-page.php (added)
-
tags/2.0.8/includes/shortcodes.php (added)
-
tags/2.0.8/includes/traffic-shape.php (added)
-
tags/2.0.8/includes/trending-legacy.php (added)
-
tags/2.0.8/includes/trending.php (added)
-
tags/2.0.8/includes/utils.php (added)
-
tags/2.0.8/includes/view-buffer.php (added)
-
tags/2.0.8/init-view-count.php (added)
-
tags/2.0.8/languages (added)
-
tags/2.0.8/languages/init-view-count-vi-63489dfd3f2bb853537b7a37ca925d0b.json (added)
-
tags/2.0.8/languages/init-view-count-vi.mo (added)
-
tags/2.0.8/languages/init-view-count-vi.po (added)
-
tags/2.0.8/languages/init-view-count.pot (added)
-
tags/2.0.8/readme.txt (added)
-
tags/2.0.8/templates (added)
-
tags/2.0.8/templates/ranking.php (added)
-
tags/2.0.8/templates/view-list-details.php (added)
-
tags/2.0.8/templates/view-list-full.php (added)
-
tags/2.0.8/templates/view-list-grid.php (added)
-
tags/2.0.8/templates/view-list-sidebar.php (added)
-
tags/2.0.8/uninstall.php (added)
-
trunk/includes/reset-schedule.php (modified) (1 diff)
-
trunk/includes/utils.php (modified) (2 diffs)
-
trunk/init-view-count.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
init-view-count/trunk/includes/reset-schedule.php
r3801436 r3847213 232 232 init_plugin_suite_view_count_flush_meta_cache_many( $touched ); 233 233 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 234 240 $summary = array( 235 241 'total_posts' => count( $posts ), -
init-view-count/trunk/includes/utils.php
r3801436 r3847213 149 149 $locked = 1 === (int) $wpdb->get_var( $wpdb->prepare( 'SELECT GET_LOCK(%s, %d)', $lock_name, 3 ) ); 150 150 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 ) { 153 180 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Xem giải thích ở init_plugin_suite_view_count_atomic_increment(). 154 181 $wpdb->query( … … 166 193 $wpdb->query( $wpdb->prepare( 'SELECT RELEASE_LOCK(%s)', $lock_name ) ); 167 194 } 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' ); 168 198 } 169 199 -
init-view-count/trunk/init-view-count.php
r3801466 r3847213 4 4 * Description: Lightweight plugin to track real post views with scroll & delay detection, smart ranking, and flexible shortcodes. 5 5 * Plugin URI: https://inithtml.com/plugin/init-view-count/ 6 * Version: 2.0. 76 * Version: 2.0.8 7 7 * Author: Init HTML 8 8 * Author URI: https://inithtml.com/ … … 18 18 19 19 // === Constants === 20 define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_VERSION', '2.0. 7' );20 define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_VERSION', '2.0.8' ); 21 21 define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_SLUG', 'init-view-count' ); 22 22 define( 'INIT_PLUGIN_SUITE_VIEW_COUNT_DIR', plugin_dir_path( __FILE__ ) ); -
init-view-count/trunk/readme.txt
r3817525 r3847213 5 5 Tested up to: 7.2 6 6 Requires PHP: 7.4 7 Stable tag: 2.0. 77 Stable tag: 2.0.8 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 389 389 == Changelog == 390 390 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 391 396 = 2.0.7 – November 14, 2026 = 392 397 - 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.