summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/pagecount.pm
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki/Plugin/pagecount.pm')
-rw-r--r--IkiWiki/Plugin/pagecount.pm24
1 files changed, 12 insertions, 12 deletions
diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm
index 5a2301af4..8d36f057e 100644
--- a/IkiWiki/Plugin/pagecount.pm
+++ b/IkiWiki/Plugin/pagecount.pm
@@ -20,20 +20,20 @@ sub getsetup () {
sub preprocess (@) {
my %params=@_;
- $params{pages}="*" unless defined $params{pages};
+ my $pages=defined $params{pages} ? $params{pages} : "*";
- # Needs to update count whenever a page is added or removed, so
- # register a dependency.
- add_depends($params{page}, $params{pages});
-
- my @pages;
- if ($params{pages} eq "*") {
- @pages=keys %pagesources;
- }
- else {
- @pages=pagespec_match_list([keys %pagesources], $params{pages}, location => $params{page});
+ # Just get a list of all the pages, and count the items in it.
+ # Use a presence dependency to only update when pages are added
+ # or removed.
+
+ if ($pages eq '*') {
+ # optimisation to avoid needing to try matching every page
+ add_depends($params{page}, $pages, deptype("presence"));
+ return scalar keys %pagesources;
}
- return $#pages+1;
+
+ return scalar pagespec_match_list($params{page}, $pages,
+ deptype => deptype("presence"));
}
1