Show
Ignore:
Timestamp:
05/14/08 23:35:48 (19 months ago)
Author:
bchoate
Message:

Optimized category counts gathered for category archive type.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-38/lib/MT/ArchiveType/Category.pm

    r1741 r2335  
    4242        archive_template                   => 1, 
    4343        archive_listing                    => 1, 
    44         'module_category-monthly_archives' => 1, 
     44        'module_category_archives' => 1, 
    4545    }; 
    4646} 
     
    9494    require MT::Entry; 
    9595 
     96    # issue a single count_group_by for all categories 
     97    my $cnt_iter = MT::Placement->count_group_by({ 
     98        blog_id => $blog_id, 
     99    }, { 
     100        group => [ 'category_id' ], 
     101        join => MT::Entry->join_on('id', { status => MT::Entry::RELEASE() }), 
     102    }); 
     103    my %counts; 
     104    while (my ($count, $cat_id) = $cnt_iter->()) { 
     105        $counts{$cat_id} = $count; 
     106    } 
     107 
    96108    return sub { 
    97109        while ( my $c = $iter->() ) { 
    98             my @arguments = ( 
    99                 { 
    100                     blog_id => $blog_id, 
    101                     status  => MT::Entry::RELEASE() 
    102                 }, 
    103                 { 
    104                     'join' => [ 
    105                         'MT::Placement', 'entry_id', { category_id => $c->id } 
    106                     ] 
    107                 } 
    108             ); 
    109             my $count = MT::Entry->count( @arguments ); 
     110            my $count = $counts{$c->id}; 
    110111            next unless $count || $args->{show_empty}; 
    111112            return ( $count, category => $c ); 
    112113        } 
    113         undef; 
    114       } 
     114        return (); 
     115    }; 
    115116} 
    116117