WordPress.org

Make WordPress Core

Changeset 5178


Ignore:
Timestamp:
04/04/2007 08:44:45 PM (11 years ago)
Author:
ryan
Message:

Cache category hierarchy to make cat listing faster. Phase 1. see #3985

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r5152 r5178  
    792792        $categories = get_categories( 'hide_empty=0' );
    793793
     794    $children = _get_category_hierarchy();
     795
    794796    if ( $categories ) {
    795797        ob_start();
     
    797799            if ( $category->category_parent == $parent) {
    798800                echo "\t" . _cat_row( $category, $level );
    799                 cat_rows( $category->cat_ID, $level +1, $categories );
     801                if ( isset($children[$category->cat_ID]) )
     802                    cat_rows( $category->cat_ID, $level +1, $categories );
    800803            }
    801804        }
  • trunk/wp-includes/category.php

    r5149 r5178  
    110110    }
    111111
    112     if ( $child_of || $hierarchical )
    113         $categories = & _get_cat_children($child_of, $categories);
     112    if ( $child_of || $hierarchical ) {
     113        $children = _get_category_hierarchy();
     114        if ( ! empty($children) )
     115            $categories = & _get_cat_children($child_of, $categories);
     116    }
    114117
    115118    // Update category counts to include children.
     
    261264
    262265    $category_list = array();
     266    $children = _get_category_hierarchy();
    263267    foreach ( $categories as $category ) {
    264268        if ( $category->cat_ID == $category_id )
     
    267271        if ( $category->category_parent == $category_id ) {
    268272            $category_list[] = $category;
     273            if ( !isset($children[$category->cat_ID]) )
     274                continue;
     275           
    269276            if ( $children = _get_cat_children($category->cat_ID, $categories) )
    270277                $category_list = array_merge($category_list, $children);
     
    314321}
    315322
     323function _get_category_hierarchy() {
     324    $children = get_option('category_children');
     325    if ( is_array($children) )
     326        return $children;
     327
     328    $children = array();
     329    $categories = get_categories('hide_empty=0&hierarchical=0');
     330    foreach ( $categories as $cat ) {
     331        if ( $cat->category_parent > 0 )
     332            $children[$cat->category_parent][] = $cat->cat_ID;
     333    }
     334    update_option('category_children', $children);
     335
     336    return $children;
     337}
    316338?>
  • trunk/wp-includes/functions.php

    r5163 r5178  
    750750    wp_cache_delete('all_category_ids', 'category');
    751751    wp_cache_delete('get_categories', 'category');
     752    delete_option('category_children');
    752753}
    753754
Note: See TracChangeset for help on using the changeset viewer.