From 82c6dd979513b8d63b634ddaa820417b8de08f82 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Tue, 6 Dec 2016 19:47:37 +0100 Subject: [PATCH] Don't sort pages when a unknown sort method is specified Specifying a custom sort method usually means that all pages are sort by a plugin, so Pico's default alphabetical order is overwritten anyway. Letting Pico sort the pages first and discarding the result is burned CPU time... --- lib/Pico.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Pico.php b/lib/Pico.php index 56f18f4..051a383 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -1279,6 +1279,12 @@ class Pico { // sort pages $order = $this->getConfig('pages_order'); + $orderBy = $this->getConfig('pages_order_by'); + + if (($orderBy !== 'date') && ($orderBy !== 'alpha')) { + return; + } + $alphaSortClosure = function ($a, $b) use ($order) { $aSortKey = (basename($a['id']) === 'index') ? dirname($a['id']) : $a['id']; $bSortKey = (basename($b['id']) === 'index') ? dirname($b['id']) : $b['id']; @@ -1287,7 +1293,7 @@ class Pico return $cmp * (($order === 'desc') ? -1 : 1); }; - if ($this->getConfig('pages_order_by') === 'date') { + if ($orderBy === 'date') { // sort by date uasort($this->pages, function ($a, $b) use ($alphaSortClosure, $order) { if (empty($a['time']) || empty($b['time'])) {