Only sort the list when required

This commit is contained in:
Joas Schilling 2015-03-13 09:55:13 +01:00
parent 37b827f0b2
commit 3b7aec1b7d
1 changed files with 13 additions and 2 deletions

View File

@ -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;
}