From 63995039bee70bbc1209addfd0095d2ae8342fd7 Mon Sep 17 00:00:00 2001 From: joey Date: Sat, 12 May 2007 19:17:41 +0000 Subject: [PATCH] optimise backlinks counting for pagestats, simplify function returns again --- IkiWiki/Plugin/pagestats.pm | 3 +-- IkiWiki/Render.pm | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index fdda5767a..cdde43628 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -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; } } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 37383384d..92993fd95 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -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'