Skip to content

Commit

Permalink
perf: don't loop the users without any provisioning configurations
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <[email protected]>
  • Loading branch information
kesselb authored and backportbot[bot] committed Sep 3, 2024
1 parent 9cbd6cc commit 3b1f46b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
16 changes: 11 additions & 5 deletions lib/Service/Provisioning/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,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;
}

/**
Expand Down
26 changes: 23 additions & 3 deletions tests/Unit/Service/Provisioning/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,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() {
Expand Down

0 comments on commit 3b1f46b

Please sign in to comment.