all repos — honk @ 7c7290b1d463d015e736724a7994408053b35cb5

my fork of honk

allow cleanup for shorter durations
Ted Unangst tedu@tedunangst.com
Tue, 11 Jun 2019 14:46:42 -0400
commit

7c7290b1d463d015e736724a7994408053b35cb5

parent

98ed331a897f0887650beb1084d12d497ff1dda9

2 files changed, 12 insertions(+), 4 deletions(-)

jump to
M honk.gohonk.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.goupgradedb.go

@@ -101,6 +101,6 @@ case 10:

default: log.Fatalf("can't upgrade unknown version %d", dbversion) } - cleanupdb() + cleanupdb(30) os.Exit(0) }