Show
Ignore:
Timestamp:
04/06/05 22:06:12 (4 years ago)
Author:
ogawa
Message:

performance fix and extension

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • recently-pinged-on/trunk/recently-pinged-on.pl

    r25 r27  
    11# A plugin for adding 'recently_pinged_on' option to MTEntries container 
    2 #                   by Hirotaka Ogawa (http://as-is.net/blog/) 
    32# 
    4 # Release 0.11 (Jan 29, 2005) 
     3# Release 0.12 (Feb 06, 2005) 
    54# 
    65# This software is provided as-is. You may use it for commercial or  
     
    1514    require MT::Plugin; 
    1615    my $plugin = new MT::Plugin(); 
    17     $plugin->name("recently_pinged_on Plugin 0.11"); 
     16    $plugin->name("recently_pinged_on Plugin 0.12"); 
    1817    $plugin->description("Add 'recently_ping_on' option to MTEntries container"); 
    1918    $plugin->doc_link("http://as-is.net/hacks/2005/01/recently_pinged_on_plugin.html"); 
     
    2928sub hdlr_entries { 
    3029    my ($ctx, $args, $cond) = @_; 
     30    my $recently_pinged_on = $args->{recently_pinged_on} or 
     31        return &$mt_hdlr_entries(@_); 
    3132 
    32     my $recently_pinged_on = $args->{recently_pinged_on}; 
    33     return &$mt_hdlr_entries($ctx, $args, $cond) unless $recently_pinged_on; 
     33    my $blog_id = $ctx->stash('blog_id'); 
    3434 
    3535    require MT::TBPing; 
    36     my $iter = MT::TBPing->load_iter({ blog_id => $ctx->stash('blog_id') }, 
     36    my $iter = MT::TBPing->load_iter({ blog_id => $blog_id }, 
    3737                                     { sort => 'created_on', 
    3838                                       direction => 'descend' }); 
     
    4545 
    4646        require MT::Trackback; 
    47         my $trackback = MT::Trackback->load($tb_id); 
    48         my $entry_id = $trackback->entry_id or next; 
    49  
    5047        require MT::Entry; 
    51         my $entry = MT::Entry->load($entry_id); 
    52         next if $entry->status != MT::Entry::RELEASE(); 
    53  
     48        my @args = ({ status => MT::Entry::RELEASE() }, 
     49                    { join => ['MT::Trackback', 'entry_id', { id => $tb_id }] }); 
     50        my $entry = MT::Entry->load(@args) or next; 
    5451        push(@entries, $entry); 
    5552        last if ++$count == $recently_pinged_on; 
     
    5754    } 
    5855 
     56    my $res = ''; 
    5957    my $tokens = $ctx->stash('tokens'); 
    6058    my $builder = $ctx->stash('builder'); 
    61     my $res = ''; 
    62     my $saved_entry = $ctx->stash('entry'); 
     59    my $i = 0; 
    6360    for my $e (@entries) { 
    64         $ctx->stash('entry', $e); 
    65         defined(my $out = $builder->build($ctx, $tokens)) 
    66             or return $ctx->error($ctx->errstr); 
     61        local $ctx->{__stash}{entry} = $e; 
     62        local $ctx->{current_timestamp} = $e->created_on; 
     63        local $ctx->{modification_timestamp} = $e->modified_on; 
     64        my $out = $builder->build($ctx, $tokens, { 
     65            %$cond, 
     66            EntryIfExtended => $e->text_more ? 1 : 0, 
     67            EntryIfAllowComments => $e->allow_comments, 
     68            EntryIfCommentsOpen => $e->allow_comments && $e->allow_comments eq '1', 
     69            EntryIfAllowPings => $e->allow_pings, 
     70            EntriesHeader => !$i, 
     71            EntriesFooter => !defined $entries[$i+1] 
     72            }); 
     73        return $ctx->error($ctx->errstr) unless defined $out; 
    6774        $res .= $out; 
     75        $i++; 
    6876    } 
    69     $ctx->stash('entry', $saved_entry); 
    7077    $res; 
    7178}