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

Commit ef3f86bf authored by Akhil's avatar Akhil 🙂
Browse files

Merge branch 'dev/notification-memory-leaks' into 'main'

(fix) Clear user config cache for every 1000 users

See merge request !129
parents 0bdc5a69 97965e44
Loading
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -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;
		}