2024-04-06 01:07:36 +08:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2025-03-01 14:14:00 +08:00
|
|
|
"time"
|
|
|
|
|
2024-10-31 20:38:50 +08:00
|
|
|
"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)
|
2024-10-13 13:00:51 +08:00
|
|
|
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.")
|
|
|
|
}
|