Only sort the list when required
This commit is contained in:
parent
37b827f0b2
commit
3b7aec1b7d
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue