From 3b7aec1b7d4e2e3a1ff6c1f7888189c67aa09b75 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 Mar 2015 09:55:13 +0100 Subject: [PATCH] Only sort the list when required --- lib/private/previewmanager.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/private/previewmanager.php b/lib/private/previewmanager.php index 81fa1baad61..0d3ec40c06b 100644 --- a/lib/private/previewmanager.php +++ b/lib/private/previewmanager.php @@ -15,6 +15,9 @@ class PreviewManager implements IPreview { /** @var \OCP\IConfig */ protected $config; + /** @var array */ + protected $providerListDirty = false; + /** @var array */ protected $providers = []; @@ -57,6 +60,7 @@ class PreviewManager implements IPreview { $this->providers[$mimeTypeRegex] = []; } $this->providers[$mimeTypeRegex][] = $callable; + $this->providerListDirty = true; } /** @@ -64,8 +68,15 @@ class PreviewManager implements IPreview { * @return array */ public function getProviders() { - $keys = array_map('strlen', array_keys($this->providers)); - array_multisort($keys, SORT_DESC, $this->providers); + if (!$this->config->getSystemValue('enable_previews', true)) { + return []; + } + + if ($this->providerListDirty) { + $keys = array_map('strlen', array_keys($this->providers)); + array_multisort($keys, SORT_DESC, $this->providers); + $this->providerListDirty = false; + } return $this->providers; } -- 2.39.5