From 2a7721febd6cac1af5e7f4b4949ffe066c62c837 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 5 May 2009 23:40:09 -0400 Subject: Avoid %links accumulating duplicates. (For TOVA) This is sorta an optimisation, and sorta a bug fix. In one test case I have available, it can speed a page build up from 3 minutes to 3 seconds. The root of the problem is that $links{$page} contains arrays of links, rather than hashes of links. And when a link is found, it is just pushed onto the array, without checking for dups. Now, the array is emptied before scanning a page, so there should not be a lot of opportunity for lots of duplicate links to pile up in it. But, in some cases, they can, and if there are hundreds of duplicate links in the array, then scanning it for matching links, as match_link and some other code does, becomes much more expensive than it needs to be. Perhaps the real right fix would be to change the data structure to a hash. But, the list of links is never accessed like that, you always want to iterate through it. I also looked at deduping the list in saveindex, but that does a lot of unnecessary work, and doesn't completly solve the problem. So, finally, I decided to add an add_link function that handles deduping, and make ikiwiki-transition remove the old dup links. --- ikiwiki-transition | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ikiwiki-transition') diff --git a/ikiwiki-transition b/ikiwiki-transition index 599261a09..f17868d73 100755 --- a/ikiwiki-transition +++ b/ikiwiki-transition @@ -220,6 +220,21 @@ sub moveprefs { IkiWiki::Setup::dump($setup); } +sub deduplinks { + my $dir=shift; + if (! defined $dir) { + usage(); + } + $config{wikistatedir}=$dir."/.ikiwiki"; + IkiWiki::loadindex(); + foreach my $page (keys %links) { + my %l; + $l{$_}=1 foreach @{$links{$page}}; + $links{$page}=[keys %l] + } + IkiWiki::saveindex(); +} + sub usage { print STDERR "Usage: ikiwiki-transition type ...\n"; print STDERR "Currently supported transition subcommands:\n"; @@ -229,6 +244,7 @@ sub usage { print STDERR "\tmoveprefs setupfile\n"; print STDERR "\thashpassword srcdir\n"; print STDERR "\tindexdb srcdir\n"; + print STDERR "\tdeduplinks srcdir\n"; exit 1; } @@ -253,6 +269,9 @@ elsif ($mode eq 'setupformat') { elsif ($mode eq 'moveprefs') { moveprefs(@ARGV); } +elsif ($mode eq 'deduplinks') { + deduplinks(@ARGV); +} else { usage(); } -- cgit v1.2.3 From 9f5f5543bf74362cacaa7eec10d9116b41b8179d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 6 May 2009 20:46:26 -0400 Subject: ikiwiki-transition: If passed a nonexistant srcdir, or one not containing .ikiwiki, abort with an error rather than creating it. --- debian/changelog | 7 +++++++ ikiwiki-transition | 36 +++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'ikiwiki-transition') diff --git a/debian/changelog b/debian/changelog index d4fe91b88..36f4c16fd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +ikiwiki (3.13) UNRELEASED; urgency=low + + * ikiwiki-transition: If passed a nonexistant srcdir, or one not + containing .ikiwiki, abort with an error rather than creating it. + + -- Joey Hess Wed, 06 May 2009 20:45:44 -0400 + ikiwiki (3.12) unstable; urgency=low * Re-enable python-support and add python:Depends to control file. diff --git a/ikiwiki-transition b/ikiwiki-transition index f17868d73..ce1807309 100755 --- a/ikiwiki-transition +++ b/ikiwiki-transition @@ -73,11 +73,7 @@ sub prefix_directives { } sub indexdb { - my $dir=shift; - if (! defined $dir) { - usage(); - } - $config{wikistatedir}=$dir."/.ikiwiki"; + setstatedir(shift); # Note: No lockwiki here because ikiwiki already locks it # before calling this. @@ -96,11 +92,7 @@ sub indexdb { } sub hashpassword { - my $dir=shift; - if (! defined $dir) { - usage(); - } - $config{wikistatedir}=$dir."/.ikiwiki"; + setstatedir(shift); eval q{use IkiWiki::UserInfo}; eval q{use Authen::Passphrase::BlowfishCrypt}; @@ -221,11 +213,7 @@ sub moveprefs { } sub deduplinks { - my $dir=shift; - if (! defined $dir) { - usage(); - } - $config{wikistatedir}=$dir."/.ikiwiki"; + setstatdir(shift); IkiWiki::loadindex(); foreach my $page (keys %links) { my %l; @@ -235,6 +223,24 @@ sub deduplinks { IkiWiki::saveindex(); } +sub setstatedir { + my $dir=shift; + + if (! defined $dir) { + usage(); + } + + if (! -d $dir) { + error("ikiwiki-transition: $dir does not exist"); + } + + $config{wikistatedir}=$dir."/.ikiwiki"; + + if (! -d $config{wikistatedir}) { + error("ikiwiki-transition: $config{wikistatedir} does not exist"); + } +} + sub usage { print STDERR "Usage: ikiwiki-transition type ...\n"; print STDERR "Currently supported transition subcommands:\n"; -- cgit v1.2.3