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 committed Sep 3, 2024
1 parent c937e8f commit b76e68f
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 @@ -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;
}

/**
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 @@ -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() {
Expand Down

0 comments on commit b76e68f

Please sign in to comment.