rework honkmeta deletion for flexibility
This commit is contained in:
parent
3014826f6f
commit
a144795b13
21
database.go
21
database.go
|
@ -491,7 +491,7 @@ func updatehonk(h *Honk) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = deleteextras(tx, h.ID)
|
err = deleteextras(tx, h.ID, false)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err = tx.Stmt(stmtUpdateHonk).Exec(h.Precis, h.Noise, h.Format, h.Whofore, dt, h.ID)
|
_, err = tx.Stmt(stmtUpdateHonk).Exec(h.Precis, h.Noise, h.Format, h.Whofore, dt, h.ID)
|
||||||
}
|
}
|
||||||
|
@ -527,10 +527,7 @@ func deletehonk(honkid int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = deleteextras(tx, honkid)
|
err = deleteextras(tx, honkid, true)
|
||||||
if err == nil {
|
|
||||||
_, err = tx.Stmt(stmtDeleteMeta).Exec(honkid, "nonsense")
|
|
||||||
}
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err = tx.Stmt(stmtDeleteHonk).Exec(honkid)
|
_, err = tx.Stmt(stmtDeleteHonk).Exec(honkid)
|
||||||
}
|
}
|
||||||
|
@ -583,7 +580,7 @@ func saveextras(tx *sql.Tx, h *Honk) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteextras(tx *sql.Tx, honkid int64) error {
|
func deleteextras(tx *sql.Tx, honkid int64, everything bool) error {
|
||||||
_, err := tx.Stmt(stmtDeleteDonks).Exec(honkid)
|
_, err := tx.Stmt(stmtDeleteDonks).Exec(honkid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -592,7 +589,11 @@ func deleteextras(tx *sql.Tx, honkid int64) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = tx.Stmt(stmtDeleteMeta).Exec(honkid, "oldrev")
|
if everything {
|
||||||
|
_, err = tx.Stmt(stmtDeleteAllMeta).Exec(honkid)
|
||||||
|
} else {
|
||||||
|
_, err = tx.Stmt(stmtDeleteSomeMeta).Exec(honkid)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -691,7 +692,8 @@ var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker
|
||||||
var stmtUntagged, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt
|
var stmtUntagged, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt
|
||||||
var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt
|
var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt
|
||||||
var stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt
|
var stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt
|
||||||
var stmtHonksForUserFirstClass, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *sql.Stmt
|
var stmtHonksForUserFirstClass *sql.Stmt
|
||||||
|
var stmtSaveMeta, stmtDeleteAllMeta, stmtDeleteSomeMeta, stmtUpdateHonk *sql.Stmt
|
||||||
var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt
|
var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt
|
||||||
var stmtGetTracks *sql.Stmt
|
var stmtGetTracks *sql.Stmt
|
||||||
|
|
||||||
|
@ -735,7 +737,8 @@ func prepareStatements(db *sql.DB) {
|
||||||
stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit)
|
stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit)
|
||||||
|
|
||||||
stmtSaveMeta = preparetodie(db, "insert into honkmeta (honkid, genus, json) values (?, ?, ?)")
|
stmtSaveMeta = preparetodie(db, "insert into honkmeta (honkid, genus, json) values (?, ?, ?)")
|
||||||
stmtDeleteMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus <> ?")
|
stmtDeleteAllMeta = preparetodie(db, "delete from honkmeta where honkid = ?")
|
||||||
|
stmtDeleteSomeMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus not in ('oldrev')")
|
||||||
stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?")
|
stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?")
|
||||||
stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, whofore = ?, dt = ? where honkid = ?")
|
stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, whofore = ?, dt = ? where honkid = ?")
|
||||||
|
|
Loading…
Reference in New Issue