From 7d59187e7aaa25fe7339626ceaeee23503426caa Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 30 Mar 2005 23:33:37 +0000 Subject: [PATCH] Add some more cache handling to get_category(). git-svn-id: https://develop.svn.wordpress.org/trunk@2500 602fd350-edb4-49c9-b593-d223f7449a82 --- 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;