﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
15447	Cache Post Thumbnails	TheDeadMedic	nacin	"Database queries can rapidly increase when using the post thumbnails feature, especially whilst in the loop (on average, 2 additional queries '''per post''').

Suggest caching all thumbnails for the current query - will usually drop to just two additional DB queries '''in total''', regardless of number of posts.

{{{

// only run if feature supported by theme

$thumbnail_IDs = array();
foreach ($posts as $post)
	$thumbnail_IDs[] = get_post_thumbnail_id($post->ID);

if ($thumbnail_IDs) {
	$thumbnail_IDs = array_filter( array_unique($thumbnail_IDs) );
	get_posts(array(
		'update_post_term_cache' => false,
		'include' => $thumbnail_IDs,
		'post_type' => 'attachment',
		'post_status' => 'inherit',
		'nopaging' => true
	));
}
}}}

Obviously the code above is pure example - when, and where, this is best placed I'm not sure. Perhaps hooked to the 'wp' action, so it only runs for the main query?

"	enhancement	closed	normal	3.2	Performance		normal	fixed	has-patch	
