♻️ Improve notifications mark read system

This commit is contained in:
2024-10-13 13:00:51 +08:00
parent bee9799415
commit 6ea4850459
5 changed files with 22 additions and 9 deletions

View File

@ -322,8 +322,10 @@ func DeleteAccount(id uint) error {
}
func RecycleUnConfirmAccount() {
deadline := time.Now().Add(-24 * time.Hour)
var hitList []models.Account
if err := database.C.Where("confirmed_at IS NULL").Find(&hitList).Error; err != nil {
if err := database.C.Where("confirmed_at IS NULL AND created_at <= ?", deadline).Find(&hitList).Error; err != nil {
log.Error().Err(err).Msg("An error occurred while recycling accounts...")
return
}

View File

@ -20,7 +20,8 @@ func DoAutoDatabaseCleanup() {
}
deadline := time.Now().Add(-30 * 24 * time.Hour)
database.C.Unscoped().Where("created_at <= ?", deadline).Delete(&models.Notification{})
seenDeadline := time.Now().Add(-7 * 24 * time.Hour)
database.C.Unscoped().Where("created_at <= ? OR read_at <= ?", deadline, seenDeadline).Delete(&models.Notification{})
log.Debug().Int64("affected", count).Msg("Clean up entire database accomplished.")
}