perf(2meet-data-optimizer): route HivePress's featured-listing lookup
- HivePress runs it on every listing search page from its own pre_get_posts: get_posts() with the search's meta query (still unrouted, including its sort group), meta_key hp_featured and orderby rand. The router declined both shapes, so the lookup stayed native: 2.26–2.38 s of a 2.5 s page at 1.3M listings on dev36 - a sort group (key NOT EXISTS OR key EXISTS) that no orderby uses matches every post and is dropped; meta_key without meta_value and without a meta_value sort routes as EXISTS (WP_Query turns it into that clause) - Verify: PostQueryRouterTest (featured lookup routed, meta_key with a value untouched), integration 592, unit 704, phpcs, stan; dev36 front-end - PR: PR-122 (follow-up)
This commit is contained in:
@@ -436,4 +436,47 @@ class PostQueryRouterTest extends TestCase {
|
||||
$this->assertEmpty( $query->get( 'meta_query' ), 'both clauses routed' );
|
||||
$this->assertStringContainsString( '`_stock` IS NOT NULL', $router->posts_where( '', $query ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* HivePress's featured-listing lookup (Attribute::set_search_query()): the
|
||||
* search's meta query, including its sort group, plus meta_key hp_featured,
|
||||
* ordered at random. The sort group (key NOT EXISTS OR key EXISTS) matches
|
||||
* every post, so unused for ordering it is dropped; meta_key without a
|
||||
* value or a meta_value sort tests that the key exists (2.4 PR-122).
|
||||
*/
|
||||
public function test_hivepress_featured_lookup_is_routed(): void {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
$router = new WPDO_Post_Query_Router();
|
||||
$query = $this->make_query(
|
||||
array(
|
||||
'post_type' => 'product',
|
||||
'meta_key' => '_stock',
|
||||
'orderby' => 'rand',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'relation' => 'OR',
|
||||
'price__order' => array( 'key' => '_price', 'compare' => 'NOT EXISTS', 'type' => 'DECIMAL' ),
|
||||
array( 'key' => '_price', 'compare' => 'EXISTS', 'type' => 'DECIMAL' ),
|
||||
),
|
||||
array( 'key' => '_price', 'value' => array( 10, 20 ), 'compare' => 'BETWEEN', 'type' => 'NUMERIC' ),
|
||||
),
|
||||
)
|
||||
);
|
||||
$router->pre_get_posts( $query );
|
||||
|
||||
$this->assertSame( '', $query->get( 'meta_key' ), 'meta_key routed' );
|
||||
$this->assertEmpty( array_filter( (array) $query->get( 'meta_query' ), 'is_array' ), 'sort group dropped, filter routed' );
|
||||
$where = $router->posts_where( '', $query );
|
||||
$this->assertStringContainsString( '`_stock` IS NOT NULL', $where );
|
||||
$this->assertStringContainsString( 'BETWEEN', $where );
|
||||
}
|
||||
|
||||
public function test_meta_key_with_a_value_is_left_alone(): void {
|
||||
$this->set_post_mode( 'aeav_only' );
|
||||
$router = new WPDO_Post_Query_Router();
|
||||
$query = $this->make_query( array( 'post_type' => 'product', 'meta_key' => '_stock', 'meta_value' => '5' ) );
|
||||
$router->pre_get_posts( $query );
|
||||
|
||||
$this->assertSame( '_stock', $query->get( 'meta_key' ) );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user