Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86cac78c authored by theronakpatel's avatar theronakpatel
Browse files

Reduce iteration

parent 38c8a484
Loading
Loading
Loading
Loading
Loading
+7 −13
Original line number Diff line number Diff line
@@ -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('<info>Processing all users from NextCloud (total: %d)</info>', $totalUsers));
		$userCount = 0;
		$output->writeln('<info>Processing all users from NextCloud</info>');

		$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('<info>Progress: %d processed, %d success, %d errors</info>',
					$stats['processed'], $stats['success'], $stats['errors']));
				$lastProcessed = $stats['processed'];
			}
					$userCount, $stats['success'], $stats['errors']));
			}
		});
	}

	/**