perf: don't loop the users without any provisioning configurations

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
This commit is contained in:
Daniel Kesselberg 2024-09-03 15:13:49 +02:00
Родитель c937e8f30a
Коммит b76e68f373
2 изменённых файлов: 34 добавлений и 8 удалений

Просмотреть файл

@ -100,14 +100,20 @@ class Manager {
}
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;
}
/**

Просмотреть файл

@ -30,14 +30,34 @@ class ManagerTest extends TestCase {
$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, $cnt);
$this->assertEquals(0, $count);
}
public function testProvisionSkipWithoutConfigurations(): void {
$this->mock->getParameter('userManager')
->expects($this->never())
->method('callForAllUsers');
$count = $this->manager->provision();
$this->assertEquals(0, $count);
}
public function testUpdateProvisionSingleUser() {