Add some more cache handling to get_category().
git-svn-id: http://svn.automattic.com/wordpress/trunk@2500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
14aeac1de1
commit
928cb8e0a5
|
@ -611,14 +611,23 @@ function &get_page(&$page, $output = OBJECT) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retrieves category data given a category ID or category object.
|
// Retrieves category data given a category ID or category object.
|
||||||
// The category cache is fully populated by the blog header, so we don't
|
// Handles category caching.
|
||||||
// have to worry with managing it here.
|
|
||||||
function &get_category(&$category, $output = OBJECT) {
|
function &get_category(&$category, $output = OBJECT) {
|
||||||
global $cache_categories;
|
global $cache_categories, $wpdb;
|
||||||
if (is_object($category))
|
|
||||||
|
if (is_object($category)) {
|
||||||
|
if ( ! isset($cache_categories[$category->cat_ID]))
|
||||||
|
$cache_categories[$category->cat_ID] = &$category;
|
||||||
$category = & $cache_categories[$category->cat_ID];
|
$category = & $cache_categories[$category->cat_ID];
|
||||||
else
|
} else {
|
||||||
|
if ( !isset($cache_categories[$category]) ) {
|
||||||
|
$category = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID = $category");
|
||||||
|
$category->category_id = $category->cat_ID; // Alias.
|
||||||
|
$cache_categories[$category] = & $category;
|
||||||
|
} else {
|
||||||
$category = & $cache_categories[$category];
|
$category = & $cache_categories[$category];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( $output == OBJECT ) {
|
if ( $output == OBJECT ) {
|
||||||
return $category;
|
return $category;
|
||||||
|
|
Loading…
Reference in New Issue