combine delete code into a function
This commit is contained in:
parent
11721b9ec2
commit
4d95d2290a
|
@ -234,14 +234,7 @@ func savexonk(x *Honk) {
|
|||
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 {
|
||||
|
|
32
database.go
32
database.go
|
@ -247,7 +247,7 @@ func savehonk(h *Honk) error {
|
|||
}
|
||||
}
|
||||
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 @@ func savehonk(h *Honk) error {
|
|||
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, stmtHonk
|
|||
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 @@ func prepareStatements(db *sql.DB) {
|
|||
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 (?, ?, ?, ?, ?)")
|
||||
|
|
20
web.go
20
web.go
|
@ -794,16 +794,9 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
|
|||
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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue