diff --git a/lib/Command/RecoveryWarningNotificationCommand.php b/lib/Command/RecoveryWarningNotificationCommand.php index ccc22e5eb7218d31407afa2c1b124d80b814e374..81981a08e8c8f5c4a91a0b2115f2d920ad531940 100644 --- a/lib/Command/RecoveryWarningNotificationCommand.php +++ b/lib/Command/RecoveryWarningNotificationCommand.php @@ -9,21 +9,22 @@ use OCA\EmailRecovery\Service\NotificationService; use OCA\EmailRecovery\Service\RecoveryEmailService; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; +use OCP\IUser; +use OCP\Util; use OCP\IGroupManager; use OCP\IURLGenerator; use OCP\IUserManager; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Notification\IManager; +use NCU\Config\IUserConfig; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class RecoveryWarningNotificationCommand extends Command { - private IConfig $config; private IUserManager $userManager; - private IGroupManager $groupManager; private RecoveryEmailService $recoveryEmailService; private IMailer $mailer; @@ -48,20 +49,19 @@ class RecoveryWarningNotificationCommand extends Command { private array $deleteUids = []; public function __construct( - IConfig $config, IUserManager $userManager, - IGroupManager $groupManager, RecoveryEmailService $recoveryEmailService, IMailer $mailer, IManager $notificationManager, IURLGenerator $urlGenerator, ITimeFactory $timeFactory, - NotificationService $notificationService + NotificationService $notificationService, + private IGroupManager $groupManager, + private IConfig $config, + private Util $util ) { parent::__construct(); - $this->config = $config; $this->userManager = $userManager; - $this->groupManager = $groupManager; $this->recoveryEmailService = $recoveryEmailService; $this->mailer = $mailer; $this->notificationManager = $notificationManager; @@ -209,8 +209,22 @@ class RecoveryWarningNotificationCommand extends Command { $invalidCount = 0; $errorCount = 0; $premiumSkippedCount = 0; + $cacheClearCount = 0; + $totalCount = 0; foreach ($users as $username) { + $cacheClearCount++; + $totalCount++; + // Clear the user config cache for every 10000 users + if ($cacheClearCount >= 1000) { + $currentMemoryUsage = memory_get_usage(); + $output->writeln("Current memory usage after $totalCount users: " . $this->util->humanFileSize($currentMemoryUsage)); + $userPreferences = \OCP\Server::get(IUserConfig::class); + $userPreferences->clearCacheAll(); + $currentMemoryUsage = memory_get_usage(); + $output->writeln("Current memory usage after clearing cache: " . $this->util->humanFileSize($currentMemoryUsage)); + $cacheClearCount = 0; + } try { $user = $this->getUser($username); @@ -587,7 +601,7 @@ class RecoveryWarningNotificationCommand extends Command { } private function isUserValid($user): bool { - if (!($user instanceof \OCP\IUser)) { + if (!($user instanceof IUser)) { return false; }