Make GC emails also delete orphaned verifications

This commit is contained in:
Saku Laesvuori 2023-09-29 13:48:07 +03:00
parent 04d0efb545
commit 3666f29756
Signed by: slaesvuo
GPG Key ID: 257D284A2A1D3A32
2 changed files with 8 additions and 0 deletions

View File

@ -137,6 +137,13 @@ deleteExpiredEmails time = runQuery $ delete $ do
verification <- from $ table @DBEmailVerification
where_ $ verification ^. DBEmailVerificationExpires <=. val time
deleteOrphanedVerifications :: MonadDB m => m ()
deleteOrphanedVerifications = runQuery $ delete $ do
verification <- from $ table @DBEmailVerification
where_ $ (==. val (0 :: Int)) $ subSelectCount $ do
email <- from $ table @DBEmail
where_ $ email ^. DBEmailVid ==. just (verification ^. DBEmailVerificationId)
deleteUsersWithoutEmail :: MonadDB m => m ()
deleteUsersWithoutEmail = runQuery $ delete $ do
user <- from $ table @DBUser

View File

@ -58,6 +58,7 @@ gcEmailsMain :: CLIM ()
gcEmailsMain = do
time <- currentTime
deleteExpiredEmails time
deleteOrphanedVerifications
gcApplicationsMain :: CLIM ()
gcApplicationsMain = do