simplify cleanup command
This commit is contained in:
parent
a5aa1dbdcb
commit
4aba1ba5fd
|
@ -67,7 +67,7 @@ func PostMsg(keyname string, key *rsa.PrivateKey, url string, msg []byte) error
|
|||
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 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
|
|||
}
|
||||
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()
|
||||
|
|
|
@ -27,9 +27,9 @@ A list of available emus and memes appears in the funzone.
|
|||
|
||||
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.)
|
||||
|
|
39
honk.go
39
honk.go
|
@ -1507,19 +1507,19 @@ func serve() {
|
|||
}
|
||||
}
|
||||
|
||||
func cleanupdb(days int) {
|
||||
func cleanupdb(arg string) {
|
||||
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) {
|
||||
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 @@ func main() {
|
|||
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)
|
||||
}
|
||||
arg = os.Args[2]
|
||||
}
|
||||
cleanupdb(days)
|
||||
case "reduce":
|
||||
if len(os.Args) < 3 {
|
||||
log.Fatal("need a honker name")
|
||||
}
|
||||
reducedb(os.Args[2])
|
||||
cleanupdb(arg)
|
||||
case "ping":
|
||||
if len(os.Args) < 4 {
|
||||
fmt.Printf("usage: honk ping from to\n")
|
||||
|
|
|
@ -112,6 +112,6 @@ func upgradedb() {
|
|||
default:
|
||||
log.Fatalf("can't upgrade unknown version %d", dbversion)
|
||||
}
|
||||
cleanupdb(30)
|
||||
cleanupdb("30")
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue