1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-19 16:58:37 +00:00

New cron task: delete old system notices (#19219)

Add a new cron task which deletes the old system notices.
This commit is contained in:
Pilou
2022-03-28 14:54:59 +02:00
committed by GitHub
parent 6526733a58
commit 893c8938fc
5 changed files with 48 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ package admin
import (
"context"
"fmt"
"time"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/log"
@@ -133,3 +134,13 @@ func DeleteNoticesByIDs(ids []int64) error {
Delete(new(Notice))
return err
}
// DeleteOldSystemNotices deletes all old system notices from database.
func DeleteOldSystemNotices(olderThan time.Duration) (err error) {
if olderThan <= 0 {
return nil
}
_, err = db.GetEngine(db.DefaultContext).Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Notice{})
return
}