cleanup command to collect database garbage
Ted Unangst tedu@tedunangst.com
Tue, 21 May 2019 14:06:17 -0400
3 files changed,
14 insertions(+),
0 deletions(-)
M
docs/manual.txt
→
docs/manual.txt
@@ -59,6 +59,12 @@ Custom emus may be provided by creating and populating the emus directory.
emus may be referenced when composing a honk via colon wrapping. How pleasant. This :example: will be replaced by emus/example.png. +-- cleanup + +One may occasionally run `honk cleanup` to free up internal space in the +database. (This does not run vacuum, so the file size will not immediately +shrink.) + -- proxy honk requires a TLS terminating reverse proxy be configured. It communicates
M
honk.go
→
honk.go
@@ -1302,6 +1302,11 @@ log.Fatal(err)
} } +func cleanupdb() { + db := opendatabase() + 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@@ -1403,6 +1408,8 @@ }
getconfig("servername", &serverName) prepareStatements(db) switch cmd { + case "cleanup": + cleanupdb() case "ping": if len(os.Args) < 4 { fmt.Printf("usage: honk ping from to\n")
M
upgradedb.go
→
upgradedb.go
@@ -92,5 +92,6 @@ case 8:
default: log.Fatalf("can't upgrade unknown version %d", dbversion) } + cleanupdb() os.Exit(0) }