add a reduce command to eliminate pic posters

This commit is contained in:
Ted Unangst 2019-06-08 14:26:30 -04:00
parent 02ca7e2849
commit 05f2f11525
1 changed files with 13 additions and 0 deletions

13
honk.go
View File

@ -1344,6 +1344,14 @@ func cleanupdb() {
doordie(db, "delete from files where fileid not in (select fileid from donks)") 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 stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateCombos *sql.Stmt
var stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt var stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt
var stmtHonksForUser, stmtHonksForMe, stmtSaveDub *sql.Stmt var stmtHonksForUser, stmtHonksForMe, stmtSaveDub *sql.Stmt
@ -1428,6 +1436,11 @@ func main() {
adduser() adduser()
case "cleanup": case "cleanup":
cleanupdb() cleanupdb()
case "reduce":
if len(os.Args) < 3 {
log.Fatal("need a honker name")
}
reducedb(os.Args[2])
case "ping": case "ping":
if len(os.Args) < 4 { if len(os.Args) < 4 {
fmt.Printf("usage: honk ping from to\n") fmt.Printf("usage: honk ping from to\n")