From 05f2f1152513352fb1e532fabeaf64bde3fb744e Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 8 Jun 2019 14:26:30 -0400 Subject: [PATCH] add a reduce command to eliminate pic posters --- honk.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/honk.go b/honk.go index 1aef51c..cdbd74a 100644 --- a/honk.go +++ b/honk.go @@ -1344,6 +1344,14 @@ func cleanupdb() { doordie(db, "delete from files where fileid not in (select fileid from donks)") } +func reducedb(honker string) { + db := opendatabase() + expdate := time.Now().UTC().Add(-3 * 24 * time.Hour).Format(dbtimeformat) + doordie(db, "delete from donks where honkid in (select honkid from honks where dt < ? and whofore = 0 and honker = ?)", expdate, honker) + doordie(db, "delete from honks where dt < ? and whofore = 0 and honker = ?", expdate, honker) + doordie(db, "delete from files where fileid not in (select fileid from donks)") +} + var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateCombos *sql.Stmt var stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt var stmtHonksForUser, stmtHonksForMe, stmtSaveDub *sql.Stmt @@ -1428,6 +1436,11 @@ func main() { adduser() case "cleanup": cleanupdb() + case "reduce": + if len(os.Args) < 3 { + log.Fatal("need a honker name") + } + reducedb(os.Args[2]) case "ping": if len(os.Args) < 4 { fmt.Printf("usage: honk ping from to\n")