Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable3.7] perf: don't loop the users without any provisioning configurations #10095

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading