all repos — honk @ effe0d0bff77a2164b4364450109c2d5e87955c2

my fork of honk

simplify cleanup command
Ted Unangst tedu@tedunangst.com
Mon, 15 Jul 2019 20:49:01 -0400
commit

effe0d0bff77a2164b4364450109c2d5e87955c2

parent

cf9af27e7d606ebb1f91a3c57f3fe3813d83279d

4 files changed, 20 insertions(+), 29 deletions(-)

jump to
M activity.goactivity.go

@@ -67,7 +67,7 @@ req, err := http.NewRequest("POST", url, bytes.NewReader(msg))

if err != nil { return err } - req.Header.Set("User-Agent", "honksnonk/5.0; " + serverName) + req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName) req.Header.Set("Content-Type", theonetruename) zig(keyname, key, req, msg) resp, err := client.Do(req)

@@ -120,7 +120,7 @@ at = "application/jrd+json"

} req.Header.Set("Accept", at) req.Header.Set("Accept-Encoding", "gzip") - req.Header.Set("User-Agent", "honksnonk/5.0; " + serverName) + req.Header.Set("User-Agent", "honksnonk/5.0; "+serverName) if timeout > 0 { ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel()
M docs/admin.txtdocs/admin.txt

@@ -27,9 +27,9 @@ -- cleanup

One should occasionally run `honk cleanup` to free up internal space in the database. This deletes honks older than 30 days, but not those posted by a -user. +user. `honk cleanup [days]` may be used to adjust the timeframe. -One may also run `honk reduce [honker]` to delete honks older than 3 days. +One may also run `honk cleanup [honker]` to delete honks older than 3 days. This is useful to reduce the space requirements from following image bots. (Neither command runs vacuum, so the file size will not immediately shrink.)
M honk.gohonk.go

@@ -1507,19 +1507,19 @@ log.Fatal(err)

} } -func cleanupdb(days int) { - db := opendatabase() - 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)") -} - -func reducedb(honker string) { +func cleanupdb(arg 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) + days, err := strconv.Atoi(arg) + if err != nil { + honker := arg + 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) + } else { + 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)") }

@@ -1589,7 +1589,6 @@ func ElaborateUnitTests() {

} func main() { - var err error cmd := "run" if len(os.Args) > 1 { cmd = os.Args[1]

@@ -1614,19 +1613,11 @@ switch cmd {

case "adduser": adduser() case "cleanup": - days := 30 + arg := "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") + arg = os.Args[2] } - reducedb(os.Args[2]) + cleanupdb(arg) case "ping": if len(os.Args) < 4 { fmt.Printf("usage: honk ping from to\n")
M upgradedb.goupgradedb.go

@@ -112,6 +112,6 @@ case 13:

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