From 49bf877701d89d613dcf5c2d85bd08876a636dba Mon Sep 17 00:00:00 2001 From: joey Date: Sat, 28 Oct 2006 03:27:10 +0000 Subject: * Add a separate pass to find page links, and only render each page once, instead of over and over. This is up to 8 times faster than before! (This could have introduced some subtle bugs, so it needs to be tested extensively.) --- IkiWiki/Render.pm | 64 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 27 deletions(-) (limited to 'IkiWiki/Render.pm') diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index deec539ae..026b3582e 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -13,6 +13,7 @@ sub backlinks ($) { #{{{ my @links; foreach my $p (keys %links) { next if bestlink($page, $p) eq $page; + if (grep { length $_ && bestlink($p, $_) eq $page } @{$links{$p}}) { my $href=abs2rel(htmlpage($p), dirname($page)); @@ -119,21 +120,25 @@ sub mtime ($) { #{{{ return (stat($file))[9]; } #}}} -sub findlinks ($$) { #{{{ - my $page=shift; - my $content=shift; +sub scan ($) { #{{{ + my $file=shift; - my @links; - while ($content =~ /(? $oldpagemtime{$page} || + $forcerebuild{$page}) { + debug("scanning $file"); + scan($file); + } + } + # render any updated files foreach my $file (@files) { my $page=pagename($file); @@ -278,12 +291,10 @@ sub refresh () { #{{{ } # if any files were added or removed, check to see if each page - # needs an update due to linking to them or inlining them. - # TODO: inefficient; pages may get rendered above and again here; - # problem is the bestlink may have changed and we won't know until - # now + # needs an update due to linking to them or inlining them if (@add || @del) { FILE: foreach my $file (@files) { + next if $rendered{$file}; my $page=pagename($file); foreach my $f (@add, @del) { my $p=pagename($f); @@ -301,11 +312,9 @@ FILE: foreach my $file (@files) { # Handle backlinks; if a page has added/removed links, update the # pages it links to. Also handles rebuilding dependant pages. - # TODO: inefficient; pages may get rendered above and again here; - # problem is the backlinks could be wrong in the first pass render - # above if (%rendered || @del) { foreach my $f (@files) { + next if $rendered{$f}; my $p=pagename($f); if (exists $depends{$p}) { foreach my $file (keys %rendered, @del) { @@ -347,6 +356,7 @@ FILE: foreach my $file (@files) { foreach my $link (keys %linkchanged) { my $linkfile=$pagesources{$link}; if (defined $linkfile) { + next if $rendered{$linkfile}; debug("rendering $linkfile, to update its backlinks"); render($linkfile); $rendered{$linkfile}=1; -- cgit v1.2.3