Passport/pkg/internal/services/cleaner.go

24 lines
655 B
Go
Raw Normal View History

2024-04-05 17:07:36 +00:00
package services
import (
2024-04-13 05:48:19 +00:00
"git.solsynth.dev/hydrogen/passport/pkg/database"
2024-04-05 17:07:36 +00:00
"github.com/rs/zerolog/log"
"time"
)
func DoAutoDatabaseCleanup() {
deadline := time.Now().Add(60 * time.Minute)
log.Debug().Time("deadline", deadline).Msg("Now cleaning up entire database...")
var count int64
for _, model := range database.AutoMaintainRange {
2024-04-05 17:07:36 +00:00
tx := database.C.Unscoped().Delete(model, "deleted_at >= ?", deadline)
if tx.Error != nil {
log.Error().Err(tx.Error).Msg("An error occurred when running auth context cleanup...")
}
count += tx.RowsAffected
}
log.Debug().Int64("affected", count).Msg("Clean up entire database accomplished.")
}