allow cleanup for shorter durations
This commit is contained in:
parent
889026e80d
commit
44d75b3a55
14
honk.go
14
honk.go
|
@ -1366,7 +1366,7 @@ func serve() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupdb() {
|
func cleanupdb(days int) {
|
||||||
db := opendatabase()
|
db := opendatabase()
|
||||||
rows, _ := db.Query("select userid, name from zonkers where wherefore = 'zonvoy'")
|
rows, _ := db.Query("select userid, name from zonkers where wherefore = 'zonvoy'")
|
||||||
deadthreads := make(map[int64][]string)
|
deadthreads := make(map[int64][]string)
|
||||||
|
@ -1383,7 +1383,7 @@ func cleanupdb() {
|
||||||
doordie(db, "delete 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 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 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)")
|
doordie(db, "delete from files where fileid not in (select fileid from donks)")
|
||||||
|
@ -1458,6 +1458,7 @@ func ElaborateUnitTests() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var err error
|
||||||
cmd := "run"
|
cmd := "run"
|
||||||
if len(os.Args) > 1 {
|
if len(os.Args) > 1 {
|
||||||
cmd = os.Args[1]
|
cmd = os.Args[1]
|
||||||
|
@ -1480,7 +1481,14 @@ func main() {
|
||||||
case "adduser":
|
case "adduser":
|
||||||
adduser()
|
adduser()
|
||||||
case "cleanup":
|
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":
|
case "reduce":
|
||||||
if len(os.Args) < 3 {
|
if len(os.Args) < 3 {
|
||||||
log.Fatal("need a honker name")
|
log.Fatal("need a honker name")
|
||||||
|
|
|
@ -101,6 +101,6 @@ func upgradedb() {
|
||||||
default:
|
default:
|
||||||
log.Fatalf("can't upgrade unknown version %d", dbversion)
|
log.Fatalf("can't upgrade unknown version %d", dbversion)
|
||||||
}
|
}
|
||||||
cleanupdb()
|
cleanupdb(30)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue