Changeset 53333 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
- Timestamp:
- 05/02/2022 01:58:48 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php
r53218 r53333 120 120 } 121 121 122 /* 123 * Include a hash of the query args, so that different requests are stored in 124 * separate caches. 125 * 126 * MD5 is chosen for its speed, low-collision rate, universal availability, and to stay 127 * under the character limit for `_site_transient_timeout_{...}` keys. 128 * 129 * @link https://stackoverflow.com/questions/3665247/fastest-hash-for-non-cryptographic-uses 130 */ 131 $transient_key = 'wp_remote_block_patterns_' . md5( implode( '-', $query_args ) ); 122 $transient_key = $this->get_transient_key( $query_args ); 132 123 133 124 /* … … 338 329 ); 339 330 331 $query_params['slug'] = array( 332 'description' => __( 'Limit results to those matching a pattern (slug).' ), 333 'type' => 'array', 334 ); 335 340 336 /** 341 337 * Filter collection parameters for the block pattern directory controller. … … 347 343 return apply_filters( 'rest_pattern_directory_collection_params', $query_params ); 348 344 } 345 346 /* 347 * Include a hash of the query args, so that different requests are stored in 348 * separate caches. 349 * 350 * MD5 is chosen for its speed, low-collision rate, universal availability, and to stay 351 * under the character limit for `_site_transient_timeout_{...}` keys. 352 * 353 * @link https://stackoverflow.com/questions/3665247/fastest-hash-for-non-cryptographic-uses 354 * 355 * @since 6.0.0 356 * 357 * @param array $query_args Query arguments to generate a transient key from. 358 * @return string Transient key. 359 */ 360 protected function get_transient_key( $query_args ) { 361 362 if ( isset( $query_args['slug'] ) ) { 363 // This is an additional precaution because the "sort" function expects an array. 364 $query_args['slug'] = wp_parse_list( $query_args['slug'] ); 365 366 // Empty arrays should not affect the transient key. 367 if ( empty( $query_args['slug'] ) ) { 368 unset( $query_args['slug'] ); 369 } else { 370 // Sort the array so that the transient key doesn't depend on the order of slugs. 371 sort( $query_args['slug'] ); 372 } 373 } 374 375 return 'wp_remote_block_patterns_' . md5( serialize( $query_args ) ); 376 } 349 377 }
Note: See TracChangeset
for help on using the changeset viewer.