refactor(2meet-data-optimizer-hivepress-addon): leave HivePress queries to the post router
Tests / PHP Lint (pull_request) Successful in 1m5s
Tests / Unit Tests (pull_request) Successful in 1m9s
Tests / Integration Tests (pull_request) Failing after 1m46s

- Do not bind optimize_query / optimize_search on hivepress/v1/models/{listing,vendor}/{query,search} while core's TMDO_Post_Query_Router is active: core now routes HivePress searches (filters and _sort) to the entity flat tables, and two routers would claim the same clauses
- Version 0.2.0 (released with core 1.1.0); CHANGELOG
- Verify: composer test (144, +2 binding tests); integration 49; dev36 fe.sh 9 URLs ids == native (except known flat drift)
- PR: PR-063
This commit is contained in:
2026-09-26 20:19:27 +08:00
parent 61762c49d0
commit a01314cbb1
4 changed files with 51 additions and 2 deletions
+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' );
}
}