From 22401dfbdbcf26133411b0032bac097910808357 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Mon, 17 Jun 2019 12:18:37 -0400 Subject: [PATCH] tombstones for zonks --- activity.go | 18 ++++++++++++++++++ honk.go | 5 +++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/activity.go b/activity.go index 8dc3079..fb61135 100644 --- a/activity.go +++ b/activity.go @@ -191,6 +191,19 @@ saveit: return &donk } +func iszonked(userid int64, xid string) bool { + row := stmtFindZonk.QueryRow(userid, xid) + var id int64 + err := row.Scan(&id) + if err == nil { + return true + } + if err != sql.ErrNoRows { + log.Printf("err querying zonk: %s", err) + } + return false +} + func needxonk(user *WhatAbout, x *Honk) bool { if x.What == "eradicate" { return true @@ -205,6 +218,10 @@ func needxonkid(user *WhatAbout, xid string) bool { if strings.HasPrefix(xid, user.URL+"/h/") { return false } + if iszonked(user.ID, xid) { + log.Printf("already zonked: %s", xid) + return false + } row := stmtFindXonk.QueryRow(user.ID, xid) var id int64 err := row.Scan(&id) @@ -228,6 +245,7 @@ func savexonk(user *WhatAbout, x *Honk) { log.Printf("error eradicating: %s", err) } } + stmtSaveZonker.Exec(user.ID, x.XID, "zonk") return } log.Printf("saving xonk: %s", x.XID) diff --git a/honk.go b/honk.go index cf7103c..136df98 100644 --- a/honk.go +++ b/honk.go @@ -1424,7 +1424,7 @@ var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateCombos var stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt var stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt -var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt +var stmtFindZonk, stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker *sql.Stmt @@ -1473,7 +1473,8 @@ func prepareStatements(db *sql.DB) { stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?") stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?") stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zurl' or wherefore = 'zword')") - stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ?") + stmtFindZonk = preparetodie(db, "select zonkerid from zonkers where userid = ? and name = ? and wherefore = 'zonk'") + stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?") stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)")