From b76e68f37352f93dd28bc70c2addf1b9f75ee1af Mon Sep 17 00:00:00 2001 From: Daniel Kesselberg Date: Tue, 3 Sep 2024 15:13:49 +0200 Subject: [PATCH] perf: don't loop the users without any provisioning configurations Signed-off-by: Daniel Kesselberg --- lib/Service/Provisioning/Manager.php | 16 ++++++++---- .../Unit/Service/Provisioning/ManagerTest.php | 26 ++++++++++++++++--- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/Service/Provisioning/Manager.php b/lib/Service/Provisioning/Manager.php index bc69f64e8f..119633966f 100644 --- a/lib/Service/Provisioning/Manager.php +++ b/lib/Service/Provisioning/Manager.php @@ -100,14 +100,20 @@ public function getConfigs(): array { } public function provision(): int { - $cnt = 0; + $counter = 0; + $configs = $this->getConfigs(); - $this->userManager->callForAllUsers(function (IUser $user) use ($configs, &$cnt) { - if ($this->provisionSingleUser($configs, $user) === true) { - $cnt++; + if (count($configs) === 0) { + return $counter; + } + + $this->userManager->callForAllUsers(function (IUser $user) use ($configs, &$counter) { + if ($this->provisionSingleUser($configs, $user)) { + $counter++; } }); - return $cnt; + + return $counter; } /** diff --git a/tests/Unit/Service/Provisioning/ManagerTest.php b/tests/Unit/Service/Provisioning/ManagerTest.php index def8e9ad24..e9d95a928f 100644 --- a/tests/Unit/Service/Provisioning/ManagerTest.php +++ b/tests/Unit/Service/Provisioning/ManagerTest.php @@ -30,14 +30,34 @@ protected function setUp(): void { $this->manager = $this->mock->getService(); } - public function testProvision() { + public function testProvision(): void { + $config = new Provisioning(); + $config->setId(1); + $config->setProvisioningDomain('batman.com'); + $config->setEmailTemplate('%USER%@batman.com'); + + $this->mock->getParameter('provisioningMapper') + ->expects($this->once()) + ->method('getAll') + ->willReturn([$config]); + $this->mock->getParameter('userManager') ->expects($this->once()) ->method('callForAllUsers'); - $cnt = $this->manager->provision(); + $count = $this->manager->provision(); + + $this->assertEquals(0, $count); + } + + public function testProvisionSkipWithoutConfigurations(): void { + $this->mock->getParameter('userManager') + ->expects($this->never()) + ->method('callForAllUsers'); + + $count = $this->manager->provision(); - $this->assertEquals(0, $cnt); + $this->assertEquals(0, $count); } public function testUpdateProvisionSingleUser() {