From 20e77a1e9ee879d1830ff6285c68bb43e41bca6d Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:03:26 +0100 Subject: [PATCH] feat: optimise --- app/controllers/api/account.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index d99776e560..b4973da931 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -223,13 +223,12 @@ $createSession = function (string $userId, string $secret, Request $request, Res throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed saving user to DB'); } - $sessionAlertsEnabled = $project->getAttribute('auths', [])['sessionAlerts'] ?? false; - $isFirstSession = $dbForProject->count('sessions', [ - Query::equal('userId', [$user->getId()]), - ]) === 1; - - if ($sessionAlertsEnabled && !$isFirstSession) { - sendSessionAlert($locale, $user, $project, $session, $queueForMails); + if ($$project->getAttribute('auths', [])['sessionAlerts'] ?? false) { + if ($dbForProject->count('sessions', [ + Query::equal('userId', [$user->getId()]), + ]) !== 1) { + sendSessionAlert($locale, $user, $project, $session, $queueForMails); + } } $queueForEvents @@ -908,16 +907,14 @@ App::post('/v1/account/sessions/email') ->setParam('sessionId', $session->getId()) ; - $sessionAlertsEnabled = $project->getAttribute('auths', [])['sessionAlerts'] ?? false; - $isFirstSession = $dbForProject->count('sessions', [ - Query::equal('userId', [$user->getId()]), - ]) === 1; - - if ($sessionAlertsEnabled && !$isFirstSession) { - sendSessionAlert($locale, $user, $project, $session, $queueForMails); + if ($$project->getAttribute('auths', [])['sessionAlerts'] ?? false) { + if ($dbForProject->count('sessions', [ + Query::equal('userId', [$user->getId()]), + ]) !== 1) { + sendSessionAlert($locale, $user, $project, $session, $queueForMails); + } } - $response->dynamic($session, Response::MODEL_SESSION); });