[wp-trac] [WordPress Trac] #13989: Recent Comments widget optimization
WordPress Trac
wp-trac at lists.automattic.com
Sat Jun 19 06:30:37 UTC 2010
#13989: Recent Comments widget optimization
--------------------------+-------------------------------------------------
Reporter: dd32 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 3.1
Component: Optimization | Version: 3.0
Severity: normal | Keywords: has-patch
--------------------------+-------------------------------------------------
Currently when permalinks are enabled, the recent comments widget will
call get_post() on each parent post to retrieve its permalink.
In the event that the posts the recent comments are on are not in the
current query (for example, posts on old posts, or if we're currently on a
singular view), then get_post() will perform a SQL query to load the
postdata.
The attached patch introduces a {{{cache_posts($post_ids, $term_cache,
$postmeta_cache);}}} function to mass load/cache a set of posts through
the usage of WP_Query
The function is smart enough not to query for posts which are already in
the Object cache (ie. If the comments are on the current page, it'll skip,
or if its in a memory cache)
An example of the SQL query generated by this query:
{{{
SELECT wp_posts . *
FROM wp_posts
WHERE 1 =1
AND wp_posts.ID IN ( 95, 98, 106 )
AND wp_posts.post_type IN ('post', 'page', 'attachment', 'wiki', 'note',
'odd')
AND (wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-
draft')
}}}
Explain'd:
{{{
id select_type table type possible_keys
key key_len ref rows Extra
1 SIMPLE wp_posts range PRIMARY,type_status_date
PRIMARY 8 NULL 3 Using where
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/13989>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list