diff options
author | Pilou <pierre-louis@libregerbil.fr> | 2022-03-28 14:54:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-28 13:54:59 +0100 |
commit | 893c8938fc81166f386ff203f2129497ceddbc32 (patch) | |
tree | a4b0d79b4c4871932d344fa9c29a0aaa77139951 /models/admin | |
parent | 6526733a58632086d51ce7211b3a4dc75dbbef90 (diff) | |
download | gitea-893c8938fc81166f386ff203f2129497ceddbc32.tar.gz gitea-893c8938fc81166f386ff203f2129497ceddbc32.zip |
New cron task: delete old system notices (#19219)
Add a new cron task which deletes the old system notices.
Diffstat (limited to 'models/admin')
-rw-r--r-- | models/admin/notice.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/models/admin/notice.go b/models/admin/notice.go index daf095f680..77277e4b2d 100644 --- a/models/admin/notice.go +++ b/models/admin/notice.go @@ -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 +} |