Let E be the number of dependencies per page of the form "A depends on B and
nothing else", let D be the number of other dependencies per page,
let P be the total number of pages, and let C be the number of changed
pages in a refresh.
This patch should speed up a refresh from O(E*C*P + D*C*P) to
O(C + E*P + D*C*P), assuming that hash lookups are O(1).
In practice, plugins like inline and map produce a lot of these very simple
dependencies, and my album plugin's combination of inline with a large
number of pages causes it to suffer particularly badly.
In testing on a wiki with about 7000 objects (3500 full pages, 3500
images), a full rebuild continued to take about 5:30, and a refresh
after touching about 350 pages and 350 images reduced from 5:30 to 1:30.
As with my previous optimizations, this change will result in downgrades not
working correctly until the wiki is rebuilt.
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
%pagestate %wikistate %renderedfiles %oldrenderedfiles
%pagesources %destsources %depends %hooks %forcerebuild
use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
%pagestate %wikistate %renderedfiles %oldrenderedfiles
%pagesources %destsources %depends %hooks %forcerebuild
+ %loaded_plugins %depends_exact};
use Exporter q{import};
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
pagespec_match_list bestlink htmllink readfile writefile
pagetype srcfile pagename displaytime will_render gettext urlto
targetpage add_underlay pagetitle titlepage linkpage
use Exporter q{import};
our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
pagespec_match_list bestlink htmllink readfile writefile
pagetype srcfile pagename displaytime will_render gettext urlto
targetpage add_underlay pagetitle titlepage linkpage
- newpagefile inject add_link
+ newpagefile inject add_link add_depends_exact
%config %links %pagestate %wikistate %renderedfiles
%pagesources %destsources);
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
%config %links %pagestate %wikistate %renderedfiles
%pagesources %destsources);
our $VERSION = 3.00; # plugin interface version, next is ikiwiki version
%oldrenderedfiles=%pagectime=();
if (! $config{rebuild}) {
%pagesources=%pagemtime=%oldlinks=%links=%depends=
%oldrenderedfiles=%pagectime=();
if (! $config{rebuild}) {
%pagesources=%pagemtime=%oldlinks=%links=%depends=
- %destsources=%renderedfiles=%pagecase=%pagestate=();
+ %destsources=%renderedfiles=%pagecase=%pagestate=
+ %depends_exact=();
}
my $in;
if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
}
my $in;
if (! open ($in, "<", "$config{wikistatedir}/indexdb")) {
$links{$page}=$d->{links};
$oldlinks{$page}=[@{$d->{links}}];
}
$links{$page}=$d->{links};
$oldlinks{$page}=[@{$d->{links}}];
}
+ if (exists $d->{depends_exact}) {
+ $depends_exact{$page}={
+ map { $_ => 1 } @{$d->{depends_exact}}
+ };
+ }
if (exists $d->{dependslist}) {
$depends{$page}={
map { $_ => 1 } @{$d->{dependslist}}
if (exists $d->{dependslist}) {
$depends{$page}={
map { $_ => 1 } @{$d->{dependslist}}
$index{page}{$src}{dependslist} = [ keys %{$depends{$page}} ];
}
$index{page}{$src}{dependslist} = [ keys %{$depends{$page}} ];
}
+ if (exists $depends_exact{$page}) {
+ $index{page}{$src}{depends_exact} = [ keys %{$depends_exact{$page}} ];
+ }
+
if (exists $pagestate{$page}) {
foreach my $id (@hookids) {
foreach my $key (keys %{$pagestate{$page}{$id}}) {
if (exists $pagestate{$page}) {
foreach my $id (@hookids) {
foreach my $key (keys %{$pagestate{$page}{$id}}) {
+sub add_depends_exact ($$) {
+ my $page = shift;
+ my $dep = shift;
+
+ $depends_exact{$page}{$dep} = 1;
+}
+
sub file_pruned ($$) {
require File::Spec;
my $file=File::Spec->canonpath(shift);
sub file_pruned ($$) {
require File::Spec;
my $file=File::Spec->canonpath(shift);
if (defined $type) {
my $page=pagename($file);
delete $depends{$page};
if (defined $type) {
my $page=pagename($file);
delete $depends{$page};
+ delete $depends_exact{$page};
will_render($page, htmlpage($page), 1);
return if $type=~/^_/;
will_render($page, htmlpage($page), 1);
return if $type=~/^_/;
}
else {
delete $depends{$file};
}
else {
delete $depends{$file};
+ delete $depends_exact{$file};
will_render($file, $file, 1);
if ($config{hardlink}) {
will_render($file, $file, 1);
if ($config{hardlink}) {
# internal pages are not rendered
my $page=pagename($file);
delete $depends{$page};
# internal pages are not rendered
my $page=pagename($file);
delete $depends{$page};
+ delete $depends_exact{$page};
foreach my $old (@{$renderedfiles{$page}}) {
delete $destsources{$old};
}
foreach my $old (@{$renderedfiles{$page}}) {
delete $destsources{$old};
}
if (%rendered || @del || @internal) {
my @changed=(keys %rendered, @del);
if (%rendered || @del || @internal) {
my @changed=(keys %rendered, @del);
+ my %changedpages = map { pagename($_) => 1 } @changed;
+
# rebuild dependant pages
F: foreach my $f (@$files) {
next if $rendered{$f};
my $p=pagename($f);
# rebuild dependant pages
F: foreach my $f (@$files) {
next if $rendered{$f};
my $p=pagename($f);
+
+ if (exists $depends_exact{$p}) {
+ foreach my $d (keys %{$depends_exact{$p}}) {
+ if (exists $changedpages{$d}) {
+ debug(sprintf(gettext("building %s, which depends on %s"), $f, $p));
+ render($f);
+ $rendered{$f}=1;
+ next F;
+ }
+ }
+ }
+
if (exists $depends{$p}) {
foreach my $d (keys %{$depends{$p}}) {
my $sub=pagespec_translate($d);
if (exists $depends{$p}) {
foreach my $d (keys %{$depends{$p}}) {
my $sub=pagespec_translate($d);