Paperclip/pkg/internal/services/cleaner.go

25 lines
678 B
Go
Raw Normal View History

2024-05-17 07:59:51 +00:00
package services
import (
2024-06-16 15:24:54 +00:00
database2 "git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
2024-05-17 07:59:51 +00:00
"time"
"github.com/rs/zerolog/log"
)
func DoAutoDatabaseCleanup() {
deadline := time.Now().Add(60 * time.Minute)
log.Debug().Time("deadline", deadline).Msg("Now cleaning up entire database...")
var count int64
2024-06-16 15:24:54 +00:00
for _, model := range database2.AutoMaintainRange {
tx := database2.C.Unscoped().Delete(model, "deleted_at >= ?", deadline)
2024-05-17 07:59:51 +00:00
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.")
}