Merge pull request 'hardening 2.1: 2meet-data-optimizer-hivepress-addon 0.2.0 (staged rollout)' (#2) from hardening/2.1 into main
Tests / PHP Lint (push) Successful in 7s
Tests / Integration Tests (push) Failing after 1m15s
Tests / Unit Tests (push) Successful in 1m22s

This commit was merged in pull request #2.
This commit is contained in:
2026-09-26 21:19:51 +08:00
4 changed files with 51 additions and 2 deletions
+2 -2
View File
@@ -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__ );
+14
View File
@@ -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,連真實
@@ -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(
+29
View File
@@ -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<int, mixed> 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' );
}
}