[wp-trac] [WordPress Trac] #36711: Add caching to get_page_by_path
WordPress Trac
noreply at wordpress.org
Sat May 21 09:59:27 UTC 2016
#36711: Add caching to get_page_by_path
-------------------------------------------------+-------------------------
Reporter: spacedmonkey | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 4.6
Component: Posts, Post Types | Version: 2.1
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests dev- | Focuses:
feedback | performance
-------------------------------------------------+-------------------------
Comment (by spacedmonkey):
I have been running a patch similar patch on production ( millions of
requests a day ) and it has massively cut down the number of queries to
the posts table. Very happy to see this in core :D
Couple of notes on 36711.5.patch
The follow lines are problem for me.
{{{#!php
if ( false !== $cached ) {
return get_post( $cached );
}
}}}
I believe they should look something like this.
{{{#!php
if ( false !== $cached ) {
if ( $cached ) {
return get_post( $cached, $output );
}
return;
}
}}}
Fixes 2 issues.
1. The format of output is now respected.
2. If $cached is 0 ( nothing found ), it will not give that to get_post.
If you give get_post an empty value (null/0/false) it will just return the
current post, which is incorrect. If the cached value is 0, the function
should just return.
One thing I have never understand about this function, why doesn't it
return anything if nothing is found? It could at least return null or
false.
Once we have worked through all the issues with this patch, similar
caching can be applied to the get_page_by_title function as well :D
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36711#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list