From 41a9cf5f6f2f6250cdd35f1cca1c9f737c6a9b91 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Thu, 5 May 2022 14:55:32 -0400 Subject: [PATCH] should delete old pubkeys after a while and refresh --- database.go | 3 ++- web.go | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/database.go b/database.go index 0bc844b..c443cbd 100644 --- a/database.go +++ b/database.go @@ -1096,7 +1096,7 @@ var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt var stmtCheckFileData *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt var stmtUntagged, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt -var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt +var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker, stmtDeleteOldXonkers *sql.Stmt var stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtHonksForUserFirstClass *sql.Stmt var stmtSaveMeta, stmtDeleteAllMeta, stmtDeleteOneMeta, stmtDeleteSomeMeta, stmtUpdateHonk *sql.Stmt @@ -1176,6 +1176,7 @@ func prepareStatements(db *sql.DB) { stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?") stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor, dt) values (?, ?, ?, ?)") stmtDeleteXonker = preparetodie(db, "delete from xonkers where name = ? and flavor = ? and dt < ?") + stmtDeleteOldXonkers = preparetodie(db, "delete from xonkers where flavor = ? and dt < ?") stmtRecentHonkers = preparetodie(db, "select distinct(honker) from honks where userid = ? and honker not in (select xid from honkers where userid = ? and flavor = 'sub') order by honkid desc limit 100") stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where honkid = ?") stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where honkid = ?") diff --git a/web.go b/web.go index 9a84518..54ed67f 100644 --- a/web.go +++ b/web.go @@ -2378,6 +2378,11 @@ var preservehooks []func() func bgmonitor() { for { + when := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat) + _, err := stmtDeleteOldXonkers.Exec("pubkey", when) + if err != nil { + elog.Printf("error deleting old xonkers: %s", err) + } time.Sleep(50 * time.Minute) } }