From 86cac78cd45b45ff5b8c241eadd8036eb5f4a188 Mon Sep 17 00:00:00 2001 From: theronakpatel Date: Tue, 8 Jul 2025 23:40:50 +0530 Subject: [PATCH] Reduce iteration --- lib/Command/SyncMissingUsersToCommon.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/Command/SyncMissingUsersToCommon.php b/lib/Command/SyncMissingUsersToCommon.php index 5df790f5..2ceba720 100644 --- a/lib/Command/SyncMissingUsersToCommon.php +++ b/lib/Command/SyncMissingUsersToCommon.php @@ -118,23 +118,17 @@ class SyncMissingUsersToCommon extends Command { * Process all users from NextCloud */ private function processAllUsers(string $ipAddress, bool $isDryRun, OutputInterface $output, array &$stats): void { - $allUsers = []; - $this->userManager->callForAllUsers(function (IUser $user) use (&$allUsers) { - $allUsers[] = $user; - }); - $totalUsers = count($allUsers); - $output->writeln(sprintf('Processing all users from NextCloud (total: %d)', $totalUsers)); + $userCount = 0; + $output->writeln('Processing all users from NextCloud'); - $lastProcessed = 0; - foreach ($allUsers as $user) { - $before = $stats['processed']; + $this->userManager->callForAllUsers(function (IUser $user) use (&$userCount, $ipAddress, $isDryRun, $output, &$stats) { $this->processSingleUser($user->getUID(), $ipAddress, $isDryRun, $output, $stats); - if ($stats['processed'] > 0 && $stats['processed'] % 100 === 0 && $stats['processed'] !== $lastProcessed) { + $userCount++; + if ($userCount > 0 && $userCount % 100 === 0) { $output->writeln(sprintf('Progress: %d processed, %d success, %d errors', - $stats['processed'], $stats['success'], $stats['errors'])); - $lastProcessed = $stats['processed']; + $userCount, $stats['success'], $stats['errors'])); } - } + }); } /** -- GitLab