aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authora1012112796 <1012112796@qq.com>2021-05-01 20:17:02 +0800
committerGitHub <noreply@github.com>2021-05-01 14:17:02 +0200
commitae6d7860be6a5f5032f86369af3adcedf0ad0725 (patch)
treef11369529ab4bf4c0dd73500ec4470320dd4cf6e /models
parentca0460beb7201737510f522c1aa6d1cc7f394f72 (diff)
downloadgitea-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.go10
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
+}