all repos — honk @ 96116fdb4d4c9da30ff3c5bbd6a41c745276b67c

my fork of honk

combine delete code into a function
Ted Unangst tedu@tedunangst.com
Mon, 16 Sep 2019 17:00:50 -0400
commit

96116fdb4d4c9da30ff3c5bbd6a41c745276b67c

parent

2f24470a7751a2062381ef79e5f0a366abdb1f87

3 files changed, 28 insertions(+), 33 deletions(-)

jump to
M activity.goactivity.go

@@ -234,14 +234,7 @@ if x.What == "eradicate" {

log.Printf("eradicating %s by %s", x.XID, x.Honker) xonk := getxonk(x.UserID, x.XID) if xonk != nil { - _, err := stmtZonkDonks.Exec(xonk.ID) - if err != nil { - log.Printf("error eradicating: %s", err) - } - _, err = stmtZonkIt.Exec(xonk.ID) - if err != nil { - log.Printf("error eradicating: %s", err) - } + deletehonk(xonk.ID) } _, err := stmtSaveZonker.Exec(x.UserID, x.XID, "zonk") if err != nil {
M database.godatabase.go

@@ -247,7 +247,7 @@ return err

} } for _, o := range h.Onts { - _, err = stmtSaveOnts.Exec(strings.ToLower(o), h.ID) + _, err = stmtSaveOnt.Exec(strings.ToLower(o), h.ID) if err != nil { log.Printf("error saving ont: %s", err) return err

@@ -256,6 +256,21 @@ }

return nil } +func deletehonk(honkid int64) { + _, err := stmtDeleteDonks.Exec(honkid) + if err != nil { + log.Printf("error deleting: %s", err) + } + _, err = stmtDeleteOnts.Exec(honkid) + if err != nil { + log.Printf("error deleting: %s", err) + } + _, err = stmtDeleteHonk.Exec(honkid) + if err != nil { + log.Printf("error deleting: %s", err) + } +} + func cleanupdb(arg string) { db := opendatabase() days, err := strconv.Atoi(arg)

@@ -281,9 +296,9 @@ var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt

var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt var stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt -var stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt +var stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt -var stmtSelectOnts, stmtSaveOnts, stmtUpdateFlags, stmtClearFlags *sql.Stmt +var stmtSelectOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)

@@ -318,14 +333,15 @@ stmtHonksByConvoy = preparetodie(db, selecthonks+"where (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit)

stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit) stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags, onts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") - stmtSaveOnts = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") + stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") + stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") + stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") + stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)") + stmtDeleteDonks = preparetodie(db, "delete from donks where honkid = ?") + stmtSaveFile = preparetodie(db, "insert into files (xid, name, description, url, media, local, content) values (?, ?, ?, ?, ?, ?, ?)") stmtFileData = preparetodie(db, "select media, content from files where xid = ?") stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?") - stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)") - stmtZonkIt = preparetodie(db, "delete from honks where honkid = ?") - stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?") stmtFindFile = preparetodie(db, "select fileid from files where url = ? and local = 1") - stmtSaveFile = preparetodie(db, "insert into files (xid, name, description, url, media, local, content) values (?, ?, ?, ?, ?, ?, ?)") stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey, options from users where username = ?") stmtSaveDub = preparetodie(db, "insert into honkers (userid, name, xid, flavor) values (?, ?, ?, ?)") stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, username, rcpt, msg) values (?, ?, ?, ?, ?)")
M web.goweb.go

@@ -794,16 +794,9 @@

if wherefore == "unbonk" { xonk := getbonk(userinfo.UserID, what) if xonk != nil { - _, err := stmtZonkDonks.Exec(xonk.ID) - if err != nil { - log.Printf("error zonking: %s", err) - } - _, err = stmtZonkIt.Exec(xonk.ID) - if err != nil { - log.Printf("error zonking: %s", err) - } + deletehonk(xonk.ID) xonk = getxonk(userinfo.UserID, what) - _, err = stmtClearFlags.Exec(flagIsBonked, xonk.ID) + _, err := stmtClearFlags.Exec(flagIsBonked, xonk.ID) if err != nil { log.Printf("error unbonking: %s", err) }

@@ -816,14 +809,7 @@ log.Printf("zonking %s %s", wherefore, what)

if wherefore == "zonk" { xonk := getxonk(userinfo.UserID, what) if xonk != nil { - _, err := stmtZonkDonks.Exec(xonk.ID) - if err != nil { - log.Printf("error zonking: %s", err) - } - _, err = stmtZonkIt.Exec(xonk.ID) - if err != nil { - log.Printf("error zonking: %s", err) - } + deletehonk(xonk.ID) if xonk.Whofore == 2 || xonk.Whofore == 3 { sendzonkofsorts(xonk, user, "zonk") }