Implement automatic cleanup of unused tags with hourly scheduled deletion

This commit is contained in:
2025-06-14 17:09:57 +08:00
parent e6dd2594fd
commit ff03d9a21f
2 changed files with 40 additions and 0 deletions

View File

@@ -6,8 +6,24 @@ import (
"nysoure/server/model"
"slices"
"strings"
"time"
)
func init() {
// Start a goroutine to delete unused tags every hour
go func() {
// Wait for 1 minute to ensure the database is ready
time.Sleep(time.Minute)
for {
err := dao.ClearUnusedTags()
if err != nil {
log.Errorf("Failed to clear unused tags: %v", err)
}
time.Sleep(time.Hour)
}
}()
}
func CreateTag(uid uint, name string) (*model.TagView, error) {
canUpload, err := checkUserCanUpload(uid)
if err != nil {