diff options
author | a1012112796 <1012112796@qq.com> | 2021-05-01 20:17:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-01 14:17:02 +0200 |
commit | ae6d7860be6a5f5032f86369af3adcedf0ad0725 (patch) | |
tree | f11369529ab4bf4c0dd73500ec4470320dd4cf6e /models | |
parent | ca0460beb7201737510f522c1aa6d1cc7f394f72 (diff) | |
download | gitea-ae6d7860be6a5f5032f86369af3adcedf0ad0725.tar.gz gitea-ae6d7860be6a5f5032f86369af3adcedf0ad0725.zip |
add cron job to delete old actions from database (#15688)
that's a way to save database storage space.
Signed-off-by: a1012112796 <1012112796@qq.com>
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/models/action.go b/models/action.go index 2a84133bf8..f6170005c7 100644 --- a/models/action.go +++ b/models/action.go @@ -395,3 +395,13 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) { return cond, nil } + +// DeleteOldActions deletes all old actions from database. +func DeleteOldActions(olderThan time.Duration) (err error) { + if olderThan <= 0 { + return nil + } + + _, err = x.Where("created_unix < ?", time.Now().Add(-olderThan).Unix()).Delete(&Action{}) + return +} |