feat(2meet-data-optimizer): route meta orderby including the HivePress sort clause
- Sort shape (relation OR of NOT EXISTS + EXISTS on one key, named in orderby): drop it from meta_query, LEFT JOIN the flat table and order by its column, ties by ID - Named routed clause as the sole orderby, and meta_key + meta_value_num (meta_value on string columns) with IS NOT NULL; stay native when the column would not order like CAST(meta_value AS type), orderby has several keys, or meta_value filters - Verify: tests/live/run.php router (11/11); fe.sh price__asc / hourly_rate__desc / rating__desc ids == native - PR: PR-062
This commit is contained in:
@@ -39,7 +39,7 @@ Exit code 0 when every test passed, 1 otherwise. Output per test:
|
||||
| `shadow_write` | writes in shadow_read reach native meta (user, term, HivePress listing) |
|
||||
| `serialized` | array meta values are stored serialized in flat tables, never "Array" |
|
||||
| `resync` | dual_write / shadow_read: flat follows native after every write (4 entities × 2 modes: update, same value, delete, refused writes, stale flat, key rename by meta_id) |
|
||||
| `router` | a routed WP_Query returns the same ids, in order, as native (OR, several post types, untyped numeric compares, named orderby, LIKE, keys of two groups, NOT EXISTS with the status/date copy route); routed SQL has no GROUP BY |
|
||||
| `router` | a routed WP_Query returns the same ids, in order, as native (OR, several post types, untyped numeric compares, named orderby, LIKE, keys of two groups, NOT EXISTS with the status/date copy route, meta orderby: HivePress sort shape, named clause, meta_key + meta_value_num); routed SQL has no GROUP BY |
|
||||
| `zero_side_effect` | zone tables that were never created are never queried on save / delete |
|
||||
|
||||
## Tools (`tools/`)
|
||||
|
||||
@@ -58,7 +58,7 @@ function tmdo_live_router_query( array $args, array $ids, bool $routed ): array
|
||||
tmdo_live_assert_same( '', $wpdb->last_error, 'SQL error' );
|
||||
return array(
|
||||
'ids' => array_map( 'intval', $q->posts ),
|
||||
'routed' => ! empty( $q->get( 'wpdo_post_clauses' ) ),
|
||||
'routed' => ! empty( $q->get( 'wpdo_post_clauses' ) ) || ! empty( $q->get( 'wpdo_post_sort' ) ),
|
||||
'sql' => (string) $q->request,
|
||||
);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ TMDO_Live::test(
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'Q15 orderby on a named clause keeps the native order',
|
||||
'Q15 orderby on a named clause keeps the native order, routed',
|
||||
static function () {
|
||||
$l = tmdo_live_router_listings();
|
||||
tmdo_live_router_assert_native(
|
||||
@@ -192,7 +192,8 @@ TMDO_Live::test(
|
||||
'orderby' => 'price',
|
||||
'order' => 'ASC',
|
||||
),
|
||||
array_values( $l )
|
||||
array_values( $l ),
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
@@ -297,3 +298,45 @@ TMDO_Live::test(
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'HivePress sort shape (NOT EXISTS OR EXISTS, named clause) keeps the native order, routed',
|
||||
static function () {
|
||||
$l = tmdo_live_router_listings();
|
||||
foreach ( array( 'ASC', 'DESC' ) as $order ) {
|
||||
tmdo_live_router_assert_native(
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'relation' => 'OR',
|
||||
'price__order' => array( 'key' => 'hp_price', 'type' => 'DECIMAL', 'compare' => 'NOT EXISTS' ),
|
||||
array( 'key' => 'hp_price', 'type' => 'DECIMAL', 'compare' => 'EXISTS' ),
|
||||
),
|
||||
),
|
||||
'orderby' => 'price__order',
|
||||
'order' => $order,
|
||||
),
|
||||
array_values( $l ),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
TMDO_Live::test(
|
||||
'Q07 meta_key + meta_value_num keeps the native posts and order, routed',
|
||||
static function () {
|
||||
$l = tmdo_live_router_listings();
|
||||
tmdo_live_router_assert_native(
|
||||
array(
|
||||
'post_type' => 'hp_listing',
|
||||
'meta_key' => 'hp_price',
|
||||
'orderby' => 'meta_value_num',
|
||||
'order' => 'DESC',
|
||||
),
|
||||
array_values( $l ),
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user