trail: don't generate a costly dependency when forcing sort order
authorSimon McVittie <smcv@debian.org>
Fri, 11 Jul 2014 21:08:08 +0000 (22:08 +0100)
committerSimon McVittie <smcv@debian.org>
Fri, 11 Jul 2014 21:08:08 +0000 (22:08 +0100)
pagespec_match_list() makes the current page depend on the pagespec
being matched, so if you use [[!trailoptions sort="..."]] to force
a sort order, the trail ends up depending on internal(*) and is
rebuilt whenever anything changes. Add a new sort_pages() and use that
instead.

IkiWiki.pm
IkiWiki/Plugin/trail.pm

index e5da04a3bb86d8aa47d96cac3df679623ad707ee..be3dfce39c551b73cf4613bc8407d7c7e99d8a1f 100644 (file)
@@ -2459,6 +2459,19 @@ sub pagespec_match ($$;@) {
        return $sub->($page, @params);
 }
 
+# e.g. @pages = sort_pages("title", \@pages, reverse => "yes")
+#
+# Not exported yet, but could be in future if it is generally useful.
+# Note that this signature is not the same as IkiWiki::SortSpec::sort_pages,
+# which is "more internal".
+sub sort_pages ($$;@) {
+       my $sort = shift;
+       my $list = shift;
+       my %params = @_;
+       $sort = sortspec_translate($sort, $params{reverse});
+       return IkiWiki::SortSpec::sort_pages($sort, @$list);
+}
+
 sub pagespec_match_list ($$;@) {
        my $page=shift;
        my $pagespec=shift;
index d5fb2b5d624c1b21cf0fa9163b5b223a090e917e..476db4dcb90130ce895c9480300ac84e12c482b1 100644 (file)
@@ -319,10 +319,9 @@ sub prerender {
                }
 
                if (defined $pagestate{$trail}{trail}{sort}) {
-                       # re-sort
-                       @$members = pagespec_match_list($trail, 'internal(*)',
-                               list => $members,
-                               sort => $pagestate{$trail}{trail}{sort});
+                       @$members = IkiWiki::sort_pages(
+                               $pagestate{$trail}{trail}{sort},
+                               $members);
                }
 
                if (IkiWiki::yesno $pagestate{$trail}{trail}{reverse}) {