From 928cb8e0a5488008a61d572baf29d3bd06f99a7b Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 30 Mar 2005 23:33:37 +0000 Subject: [PATCH] Add some more cache handling to get_category(). git-svn-id: http://svn.automattic.com/wordpress/trunk@2500 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index cfebd575a0..1b19223de4 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -611,14 +611,23 @@ function &get_page(&$page, $output = 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 -// have to worry with managing it here. +// Handles category caching. function &get_category(&$category, $output = OBJECT) { - global $cache_categories; - if (is_object($category)) + global $cache_categories, $wpdb; + + if (is_object($category)) { + if ( ! isset($cache_categories[$category->cat_ID])) + $cache_categories[$category->cat_ID] = &$category; $category = & $cache_categories[$category->cat_ID]; - else - $category = & $cache_categories[$category]; + } 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]; + } + } if ( $output == OBJECT ) { return $category;