faster and simpler cleanup by deleting everything older than 30 days

This commit is contained in:
Ted Unangst 2019-05-31 03:43:08 -04:00
parent 18f8b70461
commit 9c265b9f14
1 changed files with 2 additions and 1 deletions

View File

@ -1335,7 +1335,8 @@ func cleanupdb() {
}
}
expdate := time.Now().UTC().Add(-30 * 24 * time.Hour).Format(dbtimeformat)
doordie(db, "update files set content = '', local = 0 where length(content) > 20000 and fileid in (select fileid from donks join honks on donks.honkid = honks.honkid where honks.dt < ? and whofore = 0) and fileid not in (select fileid from donks join honks on donks.honkid = honks.honkid where whofore = 2 or whofore = 3)", expdate)
doordie(db, "delete from donks where honkid in (select honkid from honks where dt < ? and whofore = 0)", expdate)
doordie(db, "delete from honks where dt < ? and whofore = 0", expdate)
doordie(db, "delete from files where fileid not in (select fileid from donks)")
}