diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-02-24 15:19:15 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-02-24 15:19:15 +0100 |
commit | d43d34c93f86ffa968158e57cb03728843ec8e93 (patch) | |
tree | f9735591c6e44727a0e4116f80e183d6f89ff38e /lib/private/activitymanager.php | |
parent | 732541448136d41b97a7fc77f6efb23d6d893f3f (diff) | |
parent | 12fc6258854eb2e9d72a8777131e2bca71075b41 (diff) | |
download | nextcloud-server-d43d34c93f86ffa968158e57cb03728843ec8e93.tar.gz nextcloud-server-d43d34c93f86ffa968158e57cb03728843ec8e93.zip |
Merge pull request #14195 from owncloud/activity-manager-performance-improvements
Activity manager performance improvements
Diffstat (limited to 'lib/private/activitymanager.php')
-rw-r--r-- | lib/private/activitymanager.php | 108 |
1 files changed, 75 insertions, 33 deletions
diff --git a/lib/private/activitymanager.php b/lib/private/activitymanager.php index 30a54fa009c..c4759120a39 100644 --- a/lib/private/activitymanager.php +++ b/lib/private/activitymanager.php @@ -40,6 +40,19 @@ class ActivityManager implements IManager { */ private $extensions = array(); + /** @var array list of filters "name" => "is valid" */ + protected $validFilters = array( + 'all' => true, + 'by' => true, + 'self' => true, + ); + + /** @var array list of type icons "type" => "css class" */ + protected $typeIcons = array(); + + /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */ + protected $specialParameters = array(); + /** * @param $app * @param $subject @@ -124,39 +137,45 @@ class ActivityManager implements IManager { } /** - * @param array $types - * @param string $filter + * @param string $method * @return array */ - function filterNotificationTypes($types, $filter) { + function getDefaultTypes($method) { + $defaultTypes = array(); foreach($this->extensions as $extension) { $c = $extension(); if ($c instanceof IExtension) { - $result = $c->filterNotificationTypes($types, $filter); - if (is_array($result)) { - $types = $result; + $types = $c->getDefaultTypes($method); + if (is_array($types)) { + $defaultTypes = array_merge($types, $defaultTypes); } } } - return $types; + return $defaultTypes; } /** - * @param string $method - * @return array + * @param string $type + * @return string */ - function getDefaultTypes($method) { - $defaultTypes = array(); + function getTypeIcon($type) { + if (isset($this->typeIcons[$type])) { + return $this->typeIcons[$type]; + } + foreach($this->extensions as $extension) { $c = $extension(); if ($c instanceof IExtension) { - $types = $c->getDefaultTypes($method); - if (is_array($types)) { - $defaultTypes = array_merge($types, $defaultTypes); + $icon = $c->getTypeIcon($type); + if (is_string($icon)) { + $this->typeIcons[$type] = $icon; + return $icon; } } } - return $defaultTypes; + + $this->typeIcons[$type] = ''; + return ''; } /** @@ -188,38 +207,30 @@ class ActivityManager implements IManager { * @return array|false */ function getSpecialParameterList($app, $text) { + if (isset($this->specialParameters[$app][$text])) { + return $this->specialParameters[$app][$text]; + } + + if (!isset($this->specialParameters[$app])) { + $this->specialParameters[$app] = array(); + } + foreach($this->extensions as $extension) { $c = $extension(); if ($c instanceof IExtension) { $specialParameter = $c->getSpecialParameterList($app, $text); if (is_array($specialParameter)) { + $this->specialParameters[$app][$text] = $specialParameter; return $specialParameter; } } } + $this->specialParameters[$app][$text] = false; return false; } /** - * @param string $type - * @return string - */ - function getTypeIcon($type) { - foreach($this->extensions as $extension) { - $c = $extension(); - if ($c instanceof IExtension) { - $icon = $c->getTypeIcon($type); - if (is_string($icon)) { - return $icon; - } - } - } - - return ''; - } - - /** * @param array $activity * @return integer|false */ @@ -264,23 +275,54 @@ class ActivityManager implements IManager { * @return boolean */ function isFilterValid($filterValue) { + if (isset($this->validFilters[$filterValue])) { + return $this->validFilters[$filterValue]; + } + foreach($this->extensions as $extension) { $c = $extension(); if ($c instanceof IExtension) { if ($c->isFilterValid($filterValue) === true) { + $this->validFilters[$filterValue] = true; return true; } } } + $this->validFilters[$filterValue] = false; return false; } /** + * @param array $types + * @param string $filter + * @return array + */ + function filterNotificationTypes($types, $filter) { + if (!$this->isFilterValid($filter)) { + return $types; + } + + foreach($this->extensions as $extension) { + $c = $extension(); + if ($c instanceof IExtension) { + $result = $c->filterNotificationTypes($types, $filter); + if (is_array($result)) { + $types = $result; + } + } + } + return $types; + } + + /** * @param string $filter * @return array */ function getQueryForFilter($filter) { + if (!$this->isFilterValid($filter)) { + return [null, null]; + } $conditions = array(); $parameters = array(); |