perf(2meet-data-optimizer): key the routed count cache on the SQL without wpdb's placeholder escape
- keyword searches carry wpdb's placeholder escape for "%" ({<hash>}), which
is new in every request, so md5(count SQL) never matched across requests
and every keyword search recounted (the 2.2 "keyword + filter routed slower
than native" finding). The key now uses remove_placeholder_escape()
- found in the 2.3 acceptance: dev36 keyword + price routed 6.2 s vs native
4.9 s; PR-091's in-process check reused one process, one escape
- Verify: PostQueryRouterFoundRowsTest (two escapes, one COUNT), integration
588, unit 703, phpcs, stan; dev36 front-end
- PR: PR-116 (2.3 acceptance)
This commit is contained in:
@@ -433,8 +433,11 @@ class TMDO_Post_Query_Router {
|
||||
global $wpdb;
|
||||
list( $count_sql, $excluded_sql ) = array_pad( (array) $count_sql, 2, '' );
|
||||
|
||||
$key = md5( $count_sql ) . ':' . wp_cache_get_last_changed( 'posts' );
|
||||
$total = wp_cache_get( $key, self::COUNT_CACHE_GROUP );
|
||||
// Keyword searches carry wpdb's placeholder escape for "%", which is new
|
||||
// in every request: without it the key would never match again.
|
||||
$stable = method_exists( $wpdb, 'remove_placeholder_escape' ) ? $wpdb->remove_placeholder_escape( $count_sql ) : $count_sql;
|
||||
$key = md5( $stable ) . ':' . wp_cache_get_last_changed( 'posts' );
|
||||
$total = wp_cache_get( $key, self::COUNT_CACHE_GROUP );
|
||||
if ( false === $total ) {
|
||||
$total = (int) $wpdb->get_var( $count_sql );
|
||||
wp_cache_set( $key, $total, self::COUNT_CACHE_GROUP, HOUR_IN_SECONDS );
|
||||
|
||||
Reference in New Issue
Block a user