Changeset 72

Show
Ignore:
Timestamp:
07/21/06 09:52:29 (2 years ago)
Author:
evdb
Message:

Changed the RSS plugin so that all the RSS is cached.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/TODO

    r68 r72  
    1 limit the length of the nodes in XML 
    2  
    3 cache output of non-id xml 
     1limit the length of the nodes in XML. This is tricky because the content is HTML and we should try not to trim it so that the HTML becomes invalid. 
    42 
    53look for if modified since headers when sending file 
    64 
    75create an 'out' page that uses cookies to store where the user should be sent. 
     6 
     7create search facility 
     8 
     9create firefox plugin for searching 
  • trunk/lib/PrlMnks/Plugin/RSS.pm

    r69 r72  
    1010 
    1111sub add_node { 
    12     my $self = shift; 
    13     my $node = shift; 
     12    my $self      = shift; 
     13    my $node      = shift; 
     14    my $node_data = $node->as_hashref; 
     15    my @to_delete = (); 
    1416 
    1517    # delete ourselves. 
    16     my $file = $self->path_to_file( 'rss', $node->node_id, 'xml' ); 
    17     unlink $file if -e $file; 
     18    push @to_delete, $node->node_id; 
    1819 
    1920    # Delete all the elders of this node. 
    20     foreach my $id ( keys %{ $node->elders || {} } ) { 
    21         my $file = $self->path_to_file( 'rss', $id, 'xml' ); 
     21    push @to_delete, keys %{ $node->elders || {} }; 
     22 
     23    # Delete the author. 
     24    push @to_delete, $node_data->{author_id}; 
     25 
     26    # Delete the category and 'top' if needed. 
     27    if ( $node->is_top ) { 
     28        push @to_delete, $node_data->{type_id}; 
     29        push @to_delete, 'top'; 
     30    } 
     31 
     32    # Always delete 'all'. 
     33    push @to_delete, 'all'; 
     34 
     35    # warn Dumper { id => $node->node_id, delete => \@to_delete } 
     36    #   if $node->is_top; 
     37 
     38    foreach my $id (@to_delete) { 
     39        next unless $id; 
     40        my $file = $self->rss_file($id); 
    2241        unlink $file if -e $file; 
    2342    } 
     
    117136      . "  limit $max_nodes"; 
    118137 
    119     warn $sql; 
     138    #warn $sql; 
    120139 
    121140    my $sth = PrlMnks::DBI->dbh->prepare($sql); 
     
    131150    # warn Dumper \@nodes; 
    132151 
    133     warn "cache this and clear it on add node"; 
    134     return $self->send_template('/rss/list.mason'); 
     152    return $self->send_template( '/rss/list.mason', { cache_to => $file } ); 
    135153} 
    136154 
     
    163181    $self->vars->{nodes}        = \@nodes; 
    164182 
    165     warn "cache this and clear it on add node"; 
    166     return $self->send_template('/rss/list.mason'); 
     183    return $self->send_template( '/rss/list.mason', { cache_to => $file } ); 
    167184} 
    168185 
     
    188205    $self->vars->{nodes}        = \@nodes; 
    189206 
    190     warn "cache this and clear it on add node"; 
    191     return $self->send_template('/rss/list.mason'); 
     207    return $self->send_template( '/rss/list.mason', { cache_to => $file } ); 
    192208} 
    193209 
  • trunk/lib/PrlMnks/Type.pm

    r53 r72  
    226226    return @ids; 
    227227} 
     228 
    2282291; 
  • trunk/t/plugin/rss/rss.t

    r69 r72  
    1313use_ok $p; 
    1414use_ok "PrlMnks::Node"; 
     15 
     16{    # Delete all the rss. 
     17    my $rss_dir = PrlMnks->shared('rss'); 
     18    `rm -rf $rss_dir`; 
     19} 
    1520 
    1621# Add a load of nodes to the database: 
     
    3944 
    4045    # Anonymous monk and perlquestions. 
    41     961, 
     46    961, 432878, 115, 
    4247); 
    4348 
     
    7176 
    7277# Check that we can get nodes by category name. 
    73 $mech->get_ok( '/rss/perlquestion.xml', 'perlquestion' ); 
    74 $mech->get_ok( '/rss/top.xml',          'top' ); 
     78# $mech->get_ok( '/rss/perlquestion.xml', 'perlquestion' ); => 
     79# $mech->get_ok( '/rss/top.xml',          'top' ); 
    7580 
    76 # Check that user nodes work too. 
     81my @tests = ( 
     82    { id => 961,   cache_id => 961,   nodes => [ 961, 508076, ], }, 
     83    { id => 'top', cache_id => 'top', nodes => [ 961, 432878, ], }, 
     84    { id => 'perlquestion', cache_id => 115, nodes => [ 432878, ], }, 
     85); 
     86 
     87# Check that other types oF node work too. 
     88foreach my $test (@tests) { 
     89    my $id = $test->{id}; 
     90 
     91    foreach my $node_id ( @{ $test->{nodes} } ) { 
     92 
     93        # diag "------------- id: $id, node_id: $node_id"; 
     94 
     95        my $cache_file = 
     96          PrlMnks->path_to_file( 'rss', $test->{cache_id}, 'xml' ); 
     97        ok !-e $cache_file, "not found $cache_file"; 
     98        $mech->get_ok("/rss/$id.xml"); 
     99        ok -e $cache_file, "found $cache_file"; 
     100 
     101        my $node = 
     102          PrlMnks::Node->new( 
     103            xml => scalar slurp "test_data/flat/$node_id-flat.xml" ); 
     104        ok $p->add_node($node), "added node '$id'"; 
     105        ok !-e $cache_file, "removed $cache_file"; 
     106 
     107    } 
     108
     109 
    77110$mech->get_ok( '/rss/961.xml', 'anonymous monk: 961' );    # Anonymous monk. 
    78111$mech->content_contains( '/508245.html', "found child node" ); 
    79112 
    80 # Delete all the rss. 
    81 my $rss_dir = PrlMnks->shared('rss'); 
    82 `rm -rf $rss_dir`; 
     113{                                                          # Delete all the rss. 
     114    my $rss_dir = PrlMnks->shared('rss'); 
     115    `rm -rf $rss_dir`; 
     116