diff --git a/2meet-data-optimizer-hivepress-addon.php b/2meet-data-optimizer-hivepress-addon.php index d4d029b..5ef54fb 100644 --- a/2meet-data-optimizer-hivepress-addon.php +++ b/2meet-data-optimizer-hivepress-addon.php @@ -3,7 +3,7 @@ * Plugin Name: 2meet Data Optimizer — Hivepress AddOn * Plugin URI: https://2meet.io/2meet-data-optimizer/hivepress * Description: HivePress + 12 擴充整合:13 adapter (core/reviews/bookings/messages/memberships/requests/favorites/statistics/tags/seo/social-links/blocks/marketplace) + 7 HPCT interceptor + 5 query interceptor + admin tab + CLI namespace - * Version: 0.1.0 + * Version: 0.2.0 * Requires at least: 6.0 * Tested up to: 6.9.4 * Requires PHP: 8.1 @@ -24,7 +24,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'TMDO_HIVEPRESS_VERSION', '0.1.0' ); +define( 'TMDO_HIVEPRESS_VERSION', '0.2.0' ); define( 'TMDO_HIVEPRESS_PATH', plugin_dir_path( __FILE__ ) ); define( 'TMDO_HIVEPRESS_URL', plugin_dir_url( __FILE__ ) ); define( 'TMDO_HIVEPRESS_FILE', __FILE__ ); diff --git a/CHANGELOG.md b/CHANGELOG.md index a792510..03aae0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,20 @@ Versioning follows [Semantic Versioning](https://semver.org/). ## [Unreleased] +--- + +## [0.2.0] — 2026-09-26 + +Released with 2meet-data-optimizer 1.1.0 (hardening 2.1, search-index mode). + +### Changed + +- HivePress model query / search hooks (`optimize_query`, `optimize_search`) + are no longer bound while core's post router is active + (`TMDO_Post_Query_Router::is_router_active()`): core routes HivePress + searches, including `_sort`, to the entity flat tables, and two routers + would claim the same clauses. + ### Added - `tests/integration/`:bootstrap(複用核心的 integration bootstrap,連真實 diff --git a/includes/hivepress/adapters/class-tmdo-hivepress-core-adapter.php b/includes/hivepress/adapters/class-tmdo-hivepress-core-adapter.php index 9326ee2..bc97ad3 100644 --- a/includes/hivepress/adapters/class-tmdo-hivepress-core-adapter.php +++ b/includes/hivepress/adapters/class-tmdo-hivepress-core-adapter.php @@ -138,8 +138,14 @@ if ( ! class_exists( 'TMDO_HivePress_Core_Adapter' ) ) { /** * Bind HivePress search query hooks at priority 20 (after HP setup). + * + * Not while core's post router serves HivePress searches from the + * entity flat tables: two routers would claim the same clauses. */ public function on_register_query_hooks(): void { + if ( class_exists( 'TMDO_Post_Query_Router' ) && TMDO_Post_Query_Router::is_router_active() ) { + return; + } foreach ( self::HOT_MODELS as $model => $post_type ) { unset( $post_type ); // Bound below by string-interpolated $model only. add_action( diff --git a/tests/unit/CoreAdapterTest.php b/tests/unit/CoreAdapterTest.php index 5e1dc03..7d5b068 100644 --- a/tests/unit/CoreAdapterTest.php +++ b/tests/unit/CoreAdapterTest.php @@ -116,4 +116,33 @@ class HivePressCoreAdapterTest extends TestCase { $this->adapter->optimize_search( $query, array() ); $this->assertEmpty( $query->get( 'wpdo_hot_clauses' ) ); } + + /** + * Register the query hooks with core's post mode set to $mode. + * + * @return array Callbacks bound to the listing query hooks. + */ + private function query_hooks_in_post_mode( string $mode ): array { + $cache = new ReflectionProperty( TMDO_Mode_Manager::class, 'cache' ); + $cache->setAccessible( true ); + $cache->setValue( null, array( 'post' => $mode, 'user' => 'disabled', 'term' => 'disabled', 'comment' => 'disabled' ) ); + unset( $GLOBALS['_wp_filter_callbacks']['hivepress/v1/models/listing/query'], $GLOBALS['_wp_filter_callbacks']['hivepress/v1/models/listing/search'] ); + try { + $this->adapter->on_register_query_hooks(); + } finally { + $cache->setValue( null, null ); + } + return array_merge( + $GLOBALS['_wp_filter_callbacks']['hivepress/v1/models/listing/query'] ?? array(), + $GLOBALS['_wp_filter_callbacks']['hivepress/v1/models/listing/search'] ?? array() + ); + } + + public function test_query_hooks_are_bound_while_the_core_post_router_is_idle(): void { + $this->assertCount( 2, $this->query_hooks_in_post_mode( 'dual_write' ) ); + } + + public function test_query_hooks_are_left_to_the_core_post_router_when_it_is_active(): void { + $this->assertSame( array(), $this->query_hooks_in_post_mode( 'shadow_read' ), 'two routers would claim the same clauses' ); + } }