aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2021-10-25 21:55:29 +0000
committerJohn Molakvoæ (Rebase PR Action) <skjnldsv@users.noreply.github.com>2021-10-26 08:59:28 +0000
commit7b1cdf1fa6b8fd75aeba0640b0172099c5fe78f6 (patch)
tree10be2ba6891e6646d0bc42bbd8572fad21b42417 /lib
parent1b366a033ad39594658ad0404a4f557dd3daad23 (diff)
downloadnextcloud-server-7b1cdf1fa6b8fd75aeba0640b0172099c5fe78f6.tar.gz
nextcloud-server-7b1cdf1fa6b8fd75aeba0640b0172099c5fe78f6.zip
Prevent unnecesary profile action registrations
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Profile/ProfileManager.php31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/private/Profile/ProfileManager.php b/lib/private/Profile/ProfileManager.php
index bf974e98e0f..a7fdfcc62f4 100644
--- a/lib/private/Profile/ProfileManager.php
+++ b/lib/private/Profile/ProfileManager.php
@@ -74,6 +74,9 @@ class ProfileManager {
/** @var ILinkAction[] */
private $actions = [];
+ /** @var null|ILinkAction[] */
+ private $sortedActions = null;
+
/**
* Array of account property actions
*/
@@ -157,21 +160,25 @@ class ProfileManager {
* @return ILinkAction[]
*/
private function getActions(IUser $targetUser, ?IUser $visitingUser): array {
- $context = $this->coordinator->getRegistrationContext();
- if ($context === null) {
- return [];
+ // If actions are already registered and sorted, return them
+ if ($this->sortedActions !== null) {
+ return $this->sortedActions;
}
foreach (self::ACCOUNT_PROPERTY_ACTIONS as $actionClass) {
- /** @var ILinkAction $provider */
- $provider = $this->container->get($actionClass);
- $this->registerAction($targetUser, $visitingUser, $provider);
+ /** @var ILinkAction $action */
+ $action = $this->container->get($actionClass);
+ $this->registerAction($targetUser, $visitingUser, $action);
}
- foreach ($context->getProfileLinkActions() as $registration) {
- /** @var ILinkAction $provider */
- $provider = $this->container->get($registration->getService());
- $this->registerAction($targetUser, $visitingUser, $provider);
+ $context = $this->coordinator->getRegistrationContext();
+
+ if ($context !== null) {
+ foreach ($context->getProfileLinkActions() as $registration) {
+ /** @var ILinkAction $action */
+ $action = $this->container->get($registration->getService());
+ $this->registerAction($targetUser, $visitingUser, $action);
+ }
}
$actionsClone = $this->actions;
@@ -179,7 +186,9 @@ class ProfileManager {
usort($actionsClone, function (ILinkAction $a, ILinkAction $b) {
return $a->getPriority() === $b->getPriority() ? 0 : ($a->getPriority() < $b->getPriority() ? -1 : 1);
});
- return $actionsClone;
+
+ $this->sortedActions = $actionsClone;
+ return $this->sortedActions;
}
/**