Optimised file statting code when scanning for modified pages; cut the number of system calls in half. (Still room for improvement.)

master
Joey Hess 2008-05-07 14:11:56 -04:00
parent 2c000c6e32
commit ec866f8370
4 changed files with 20 additions and 22 deletions

View File

@ -282,18 +282,22 @@ sub htmlpage ($) { #{{{
return targetpage($page, $config{htmlext}); return targetpage($page, $config{htmlext});
} #}}} } #}}}
sub srcfile ($;$) { #{{{ sub srcfile_stat { #{{{
my $file=shift; my $file=shift;
my $nothrow=shift; my $nothrow=shift;
return "$config{srcdir}/$file" if -e "$config{srcdir}/$file"; return "$config{srcdir}/$file", stat(_) if -e "$config{srcdir}/$file";
foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) { foreach my $dir (@{$config{underlaydirs}}, $config{underlaydir}) {
return "$dir/$file" if -e "$dir/$file"; return "$dir/$file", stat(_) if -e "$dir/$file";
} }
error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow; error("internal error: $file cannot be found in $config{srcdir} or underlay") unless $nothrow;
return; return;
} #}}} } #}}}
sub srcfile ($;$) { #{{{
return (srcfile_stat(@_))[0];
} #}}}
sub add_underlay ($) { #{{{ sub add_underlay ($) { #{{{
my $dir=shift; my $dir=shift;

View File

@ -445,7 +445,7 @@ sub genfeed ($$$$@) { #{{{
$itemtemplate->param(content => $pcontent); $itemtemplate->param(content => $pcontent);
} }
else { else {
my ($a, $b, $c, $d, $e, $f, $g, $size) = stat(srcfile($file)); my $size=(srcfile_stat($file))[8];
my $mime="unknown"; my $mime="unknown";
eval q{use File::MimeInfo}; eval q{use File::MimeInfo};
if (! $@) { if (! $@) {

View File

@ -146,12 +146,6 @@ sub genpage ($$) { #{{{
return $content; return $content;
} #}}} } #}}}
sub mtime ($) { #{{{
my $file=shift;
return (stat($file))[9];
} #}}}
sub scan ($) { #{{{ sub scan ($) { #{{{
my $file=shift; my $file=shift;
@ -283,7 +277,7 @@ sub refresh () { #{{{
if (file_pruned($_, $config{srcdir})) { if (file_pruned($_, $config{srcdir})) {
$File::Find::prune=1; $File::Find::prune=1;
} }
elsif (! -d $_ && ! -l $_) { elsif (! -l $_ && ! -d _) {
my ($f)=/$config{wiki_file_regexp}/; # untaint my ($f)=/$config{wiki_file_regexp}/; # untaint
if (! defined $f) { if (! defined $f) {
warn(sprintf(gettext("skipping bad filename %s"), $_)."\n"); warn(sprintf(gettext("skipping bad filename %s"), $_)."\n");
@ -304,7 +298,7 @@ sub refresh () { #{{{
if (file_pruned($_, $dir)) { if (file_pruned($_, $dir)) {
$File::Find::prune=1; $File::Find::prune=1;
} }
elsif (! -d $_ && ! -l $_) { elsif (! -l $_ && ! -d _) {
my ($f)=/$config{wiki_file_regexp}/; # untaint my ($f)=/$config{wiki_file_regexp}/; # untaint
if (! defined $f) { if (! defined $f) {
warn(sprintf(gettext("skipping bad filename %s"), $_)."\n"); warn(sprintf(gettext("skipping bad filename %s"), $_)."\n");
@ -314,8 +308,8 @@ sub refresh () { #{{{
# avoid underlaydir # avoid underlaydir
# override attacks; see # override attacks; see
# security.mdwn # security.mdwn
if (! -e "$config{srcdir}/$f" && if (! -l "$config{srcdir}/$f" &&
! -l "$config{srcdir}/$f") { ! -e _) {
my $page=pagename($f); my $page=pagename($f);
if (! $exists{$page}) { if (! $exists{$page}) {
push @files, $f; push @files, $f;
@ -329,7 +323,6 @@ sub refresh () { #{{{
}; };
my (%rendered, @add, @del, @internal); my (%rendered, @add, @del, @internal);
# check for added or removed pages # check for added or removed pages
foreach my $file (@files) { foreach my $file (@files) {
my $page=pagename($file); my $page=pagename($file);
@ -352,7 +345,7 @@ sub refresh () { #{{{
} }
$pagecase{lc $page}=$page; $pagecase{lc $page}=$page;
if (! exists $pagectime{$page}) { if (! exists $pagectime{$page}) {
$pagectime{$page}=mtime(srcfile($file)); $pagectime{$page}=(srcfile_stat($file))[10];
} }
} }
} }
@ -383,16 +376,15 @@ sub refresh () { #{{{
my @needsbuild; my @needsbuild;
foreach my $file (@files) { foreach my $file (@files) {
my $page=pagename($file); my $page=pagename($file);
my ($srcfile, @stat)=srcfile_stat($file);
my $mtime=mtime(srcfile($file));
if (! exists $pagemtime{$page} || if (! exists $pagemtime{$page} ||
$mtime > $pagemtime{$page} || $stat[9] > $pagemtime{$page} ||
$forcerebuild{$page}) { $forcerebuild{$page}) {
$pagemtime{$page}=$mtime; $pagemtime{$page}=$stat[9];
if (isinternal($page)) { if (isinternal($page)) {
push @internal, $file; push @internal, $file;
# Preprocess internal page in scan-only mode. # Preprocess internal page in scan-only mode.
preprocess($page, $page, readfile(srcfile($file)), 1); preprocess($page, $page, readfile($srcfile), 1);
} }
else { else {
push @needsbuild, $file; push @needsbuild, $file;
@ -535,7 +527,7 @@ sub commandline_render () { #{{{
$content=preprocess($page, $page, $content); $content=preprocess($page, $page, $content);
$content=linkify($page, $page, $content); $content=linkify($page, $page, $content);
$content=htmlize($page, $type, $content); $content=htmlize($page, $type, $content);
$pagemtime{$page}=mtime($srcfile); $pagemtime{$page}=(stat($srcfile))[9];
print genpage($page, $content); print genpage($page, $content);
exit 0; exit 0;

2
debian/changelog vendored
View File

@ -5,6 +5,8 @@ ikiwiki (2.46) UNRELEASED; urgency=low
via the `aggregate_webtrigger` configuration optiom. via the `aggregate_webtrigger` configuration optiom.
* Add pinger and pingee plugins, which allow setting up mirrors and branched * Add pinger and pingee plugins, which allow setting up mirrors and branched
wikis that automatically ping one another to stay up to date. wikis that automatically ping one another to stay up to date.
* Optimised file statting code when scanning for modified pages;
cut the number of system calls in half. (Still room for improvement.)
-- Joey Hess <joeyh@debian.org> Mon, 05 May 2008 19:34:51 -0400 -- Joey Hess <joeyh@debian.org> Mon, 05 May 2008 19:34:51 -0400