23 lines
631 B
Go
Raw Normal View History

2024-04-06 01:07:36 +08:00
package services
import (
2025-03-01 14:14:00 +08:00
"time"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"git.solsynth.dev/hypernet/passport/pkg/internal/database"
2024-04-06 01:07:36 +08:00
"github.com/rs/zerolog/log"
)
func DoAutoDatabaseCleanup() {
2024-07-12 11:25:41 +08:00
log.Debug().Msg("Now cleaning up entire database...")
2024-04-06 01:07:36 +08:00
var count int64
2024-08-24 15:17:26 +08:00
deadline := time.Now().Add(-30 * 24 * time.Hour)
seenDeadline := time.Now().Add(-7 * 24 * time.Hour)
2025-03-01 14:14:00 +08:00
tx := database.C.Unscoped().Where("created_at <= ? OR read_at <= ?", deadline, seenDeadline).Delete(&models.Notification{})
count += tx.RowsAffected
2024-08-24 15:17:26 +08:00
2024-04-06 01:07:36 +08:00
log.Debug().Int64("affected", count).Msg("Clean up entire database accomplished.")
}