optimise backlinks counting for pagestats, simplify function returns again
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sat, 12 May 2007 19:17:41 +0000 (19:17 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Sat, 12 May 2007 19:17:41 +0000 (19:17 +0000)
IkiWiki/Plugin/pagestats.pm
IkiWiki/Render.pm

index fdda5767a1266d980443788cfa8e2c576aa57713..cdde43628d7997eb1ac442bc5c5f0d9b2a3e0982 100644 (file)
@@ -35,8 +35,7 @@ sub preprocess (@) { #{{{
        foreach my $page (keys %links) {
                if (pagespec_match($page, $params{pages}, location => $params{page})) {
                        use IkiWiki::Render;
-                       my @bl = IkiWiki::backlinks($page);
-                       $counts{$page} = scalar(@{$bl[0]})+scalar(@{$bl[1]});
+                       $counts{$page} = scalar(IkiWiki::backlinks($page));
                        $max = $counts{$page} if $counts{$page} > $max;
                }
        }
index 37383384d619c02d32dcb99ab49b284f61977331..92993fd95faf4003961062d9773f7f21d16526a1 100644 (file)
@@ -44,11 +44,7 @@ sub backlinks ($) { #{{{
                               
                push @links, { url => $href, page => pagetitle($p_trimmed) };
        }
-       @links = sort { $a->{page} cmp $b->{page} } @links;
-
-       return \@links, [] if @links <= $config{numbacklinks} || ! $config{numbacklinks};
-       return [@links[0..$config{numbacklinks}-1]],
-              [@links[$config{numbacklinks}..$#links]];
+       return @links;
 } #}}}
 
 sub parentlinks ($) { #{{{
@@ -105,7 +101,16 @@ sub genpage ($$$) { #{{{
                $template->param(have_actions => 1);
        }
 
-       my ($backlinks, $more_backlinks)=backlinks($page);
+       my @backlinks=sort { $a->{page} cmp $b->{page} } backlinks($page);
+       my ($backlinks, $more_backlinks);
+       if (@backlinks <= $config{numbacklinks} || ! $config{numbacklinks}) {
+               $backlinks=\@backlinks;
+               $more_backlinks=[];
+       }
+       else {
+               $backlinks=[@backlinks[0..$config{numbacklinks}-1]];
+               $more_backlinks=[@backlinks[$config{numbacklinks}..$#backlinks]];
+       }
 
        $template->param(
                title => $page eq 'index'