allow cleanup for shorter durations
Ted Unangst tedu@tedunangst.com
Tue, 11 Jun 2019 14:46:42 -0400
2 files changed,
12 insertions(+),
4 deletions(-)
M
honk.go
→
honk.go
@@ -1366,7 +1366,7 @@ log.Fatal(err)
} } -func cleanupdb() { +func cleanupdb(days int) { db := opendatabase() rows, _ := db.Query("select userid, name from zonkers where wherefore = 'zonvoy'") deadthreads := make(map[int64][]string)@@ -1383,7 +1383,7 @@ doordie(db, "delete from donks where honkid in (select honkid from honks where userid = ? and convoy = ?)", userid, t)
doordie(db, "delete from honks where userid = ? and convoy = ?", userid, t) } } - expdate := time.Now().UTC().Add(-30 * 24 * time.Hour).Format(dbtimeformat) + expdate := time.Now().UTC().Add(-time.Duration(days) * 24 * time.Hour).Format(dbtimeformat) doordie(db, "delete from donks where honkid in (select honkid from honks where dt < ? and whofore = 0 and convoy not in (select convoy from honks where whofore = 2 or whofore = 3))", expdate) doordie(db, "delete from honks where dt < ? and whofore = 0 and convoy not in (select convoy from honks where whofore = 2 or whofore = 3)", expdate) doordie(db, "delete from files where fileid not in (select fileid from donks)")@@ -1458,6 +1458,7 @@ func ElaborateUnitTests() {
} func main() { + var err error cmd := "run" if len(os.Args) > 1 { cmd = os.Args[1]@@ -1480,7 +1481,14 @@ switch cmd {
case "adduser": adduser() case "cleanup": - cleanupdb() + days := 30 + if len(os.Args) > 2 { + days, err = strconv.Atoi(os.Args[2]) + if err != nil { + log.Fatal(err) + } + } + cleanupdb(days) case "reduce": if len(os.Args) < 3 { log.Fatal("need a honker name")
M
upgradedb.go
→
upgradedb.go
@@ -101,6 +101,6 @@ case 10:
default: log.Fatalf("can't upgrade unknown version %d", dbversion) } - cleanupdb() + cleanupdb(30) os.Exit(0) }