Recent Comments widget optimization
|Reported by:||dd32||Owned by:|
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')
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