optimise backlinks counting for pagestats, simplify function returns again

master
joey 2007-05-12 19:17:41 +00:00
parent 08d0bd7338
commit 63995039be
2 changed files with 12 additions and 8 deletions

View 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;
}
}

View 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'