Cache queries in `get_page_by_path()`.
Props spacedmonkey. Fixes #36711. Built from https://develop.svn.wordpress.org/trunk@37479 git-svn-id: http://core.svn.wordpress.org/trunk@37447 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c5c80b064d
commit
98050e404d
|
@ -4231,6 +4231,24 @@ function get_page( $page, $output = OBJECT, $filter = 'raw') {
|
|||
function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
|
||||
global $wpdb;
|
||||
|
||||
$last_changed = wp_cache_get( 'last_changed', 'posts' );
|
||||
if ( false === $last_changed ) {
|
||||
$last_changed = microtime();
|
||||
wp_cache_set( 'last_changed', $last_changed, 'posts' );
|
||||
}
|
||||
|
||||
$hash = md5( $page_path . serialize( $post_type ) );
|
||||
$cache_key = "get_page_by_path:$hash:$last_changed";
|
||||
$cached = wp_cache_get( $cache_key, 'posts' );
|
||||
if ( false !== $cached ) {
|
||||
// Special case: '0' is a bad `$page_path`.
|
||||
if ( '0' === $cached || 0 === $cached ) {
|
||||
return;
|
||||
} else {
|
||||
return get_post( $cached );
|
||||
}
|
||||
}
|
||||
|
||||
$page_path = rawurlencode(urldecode($page_path));
|
||||
$page_path = str_replace('%2F', '/', $page_path);
|
||||
$page_path = str_replace('%20', ' ', $page_path);
|
||||
|
@ -4285,6 +4303,9 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
|
|||
}
|
||||
}
|
||||
|
||||
// We cache misses as well as hits.
|
||||
wp_cache_set( $cache_key, $foundid, 'posts' );
|
||||
|
||||
if ( $foundid ) {
|
||||
return get_post( $foundid, $output );
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.6-alpha-37478';
|
||||
$wp_version = '4.6-alpha-37479';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue