[wp-trac] [WordPress Trac] #20177: Unneccessary term cache query for pages

WordPress Trac wp-trac at lists.automattic.com
Tue Sep 11 23:14:28 UTC 2012


#20177: Unneccessary term cache query for pages
--------------------------+------------------
 Reporter:  TheDeadMedic  |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  3.5
Component:  Query         |     Version:  1.5
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------
Changes (by scribu):

 * keywords:  has-patch 2nd-opinion => has-patch


Old description:

> When a request for a page is queried, {{{$post_type}}} in
> {{{WP_Query::get_posts()}}} is an empty string, which is then passed to
> {{{update_post_caches()}}}.
>
> This in turn calls {{{update_object_term_cache()}}} for 'post' (the
> default if {{{$post_type}}} is empty) instead of 'page'.
>
> Since pages don't have taxonomies (at least not in a default setup),
> we're simply wasting a query. But even if they ''did'' have, we wouldn't
> even be caching the right ones (unless of course pages were assigned the
> same taxes as posts).
>
> I would say there's two options here; review {{{WP_Query::get_posts()}}}
> to ensure the local variable {{{$post_type}}} is set correctly, or simply
> pass the string {{{any}}} to {{{update_post_caches()}}} (which will then
> correctly determine the post type(s)) - thoughts?

New description:

 When a request for a page is queried, {{{$post_type}}} in
 {{{WP_Query::get_posts()}}} is an empty string, which is then passed to
 {{{update_post_caches()}}}.

 This in turn calls {{{update_object_term_cache()}}} for 'post' (the
 default if {{{$post_type}}} is empty) instead of 'page'.

 Since pages don't have taxonomies (at least not in a default setup), we're
 simply wasting a query. But even if they ''did'' have, we wouldn't even be
 caching the right ones (unless of course pages were assigned the same
 taxes as posts).

 I would say there's two options here; review {{{WP_Query::get_posts()}}}
 to ensure the local variable {{{$post_type}}} is set correctly, or simply
 pass the string {{{'any'}}} to {{{update_post_caches()}}} (which will then
 correctly determine the post type(s)) - thoughts?

--

Comment:

 Actually, update_post_caches() already does this if you pass $post_type =
 'any' and that's the other proposed solution. Nevermind; patch looks good.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20177#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list