don't leave attachment linkage in db after deletion in case id is reused
This commit is contained in:
parent
a9d5bb35e9
commit
adcc0a1339
|
@ -275,10 +275,14 @@ func savexonk(user *WhatAbout, x *Honk) {
|
||||||
log.Printf("not deleting owner mismatch")
|
log.Printf("not deleting owner mismatch")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
xonk := getxonk(user.ID, x.RID)
|
||||||
|
if xonk != nil {
|
||||||
|
stmtZonkDonks.Exec(xonk.ID)
|
||||||
_, err := stmtZonkIt.Exec(user.ID, x.RID)
|
_, err := stmtZonkIt.Exec(user.ID, x.RID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error eradicating: %s", err)
|
log.Printf("error eradicating: %s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dt := x.Date.UTC().Format(dbtimeformat)
|
dt := x.Date.UTC().Format(dbtimeformat)
|
||||||
|
|
29
honk.go
29
honk.go
|
@ -519,7 +519,7 @@ func showhonk(w http.ResponseWriter, r *http.Request) {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
h := getxonk(name, xid)
|
h := getxonk(user.ID, xid)
|
||||||
if h == nil {
|
if h == nil {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
|
@ -618,10 +618,10 @@ func getdubs(userid int64) []*Honker {
|
||||||
return honkers
|
return honkers
|
||||||
}
|
}
|
||||||
|
|
||||||
func getxonk(name, xid string) *Honk {
|
func getxonk(userid int64, xid string) *Honk {
|
||||||
var h Honk
|
var h Honk
|
||||||
var dt, aud string
|
var dt, aud string
|
||||||
row := stmtOneXonk.QueryRow(xid)
|
row := stmtOneXonk.QueryRow(userid, xid)
|
||||||
err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID,
|
err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.XID, &h.RID,
|
||||||
&dt, &h.URL, &aud, &h.Noise, &h.Convoy)
|
&dt, &h.URL, &aud, &h.Noise, &h.Convoy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -630,10 +630,6 @@ func getxonk(name, xid string) *Honk {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if name != "" && h.Username != name {
|
|
||||||
log.Printf("user xonk mismatch")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
h.Date, _ = time.Parse(dbtimeformat, dt)
|
h.Date, _ = time.Parse(dbtimeformat, dt)
|
||||||
h.Audience = strings.Split(aud, " ")
|
h.Audience = strings.Split(aud, " ")
|
||||||
donksforhonks([]*Honk{&h})
|
donksforhonks([]*Honk{&h})
|
||||||
|
@ -729,10 +725,11 @@ func donksforhonks(honks []*Honk) {
|
||||||
|
|
||||||
func savebonk(w http.ResponseWriter, r *http.Request) {
|
func savebonk(w http.ResponseWriter, r *http.Request) {
|
||||||
xid := r.FormValue("xid")
|
xid := r.FormValue("xid")
|
||||||
|
userinfo := login.GetUserInfo(r)
|
||||||
|
|
||||||
log.Printf("bonking %s", xid)
|
log.Printf("bonking %s", xid)
|
||||||
|
|
||||||
xonk := getxonk("", xid)
|
xonk := getxonk(userinfo.UserID, xid)
|
||||||
if xonk == nil {
|
if xonk == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -741,8 +738,6 @@ func savebonk(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
convoy := xonk.Convoy
|
convoy := xonk.Convoy
|
||||||
|
|
||||||
userinfo := login.GetUserInfo(r)
|
|
||||||
|
|
||||||
dt := time.Now().UTC()
|
dt := time.Now().UTC()
|
||||||
bonk := Honk{
|
bonk := Honk{
|
||||||
UserID: userinfo.UserID,
|
UserID: userinfo.UserID,
|
||||||
|
@ -804,9 +799,11 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("zonking %s %s", wherefore, what)
|
log.Printf("zonking %s %s", wherefore, what)
|
||||||
userinfo := login.GetUserInfo(r)
|
userinfo := login.GetUserInfo(r)
|
||||||
if wherefore == "zonk" {
|
if wherefore == "zonk" {
|
||||||
xonk := getxonk(userinfo.Username, what)
|
xonk := getxonk(userinfo.UserID, what)
|
||||||
|
if xonk != nil {
|
||||||
|
stmtZonkDonks.Exec(xonk.ID)
|
||||||
stmtZonkIt.Exec(userinfo.UserID, what)
|
stmtZonkIt.Exec(userinfo.UserID, what)
|
||||||
if xonk != nil && xonk.Honker == "" {
|
if xonk.Honker == "" {
|
||||||
zonk := Honk{
|
zonk := Honk{
|
||||||
What: "zonk",
|
What: "zonk",
|
||||||
XID: xonk.XID,
|
XID: xonk.XID,
|
||||||
|
@ -818,6 +815,7 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("announcing deleted honk: %s", what)
|
log.Printf("announcing deleted honk: %s", what)
|
||||||
go honkworldwide(user, &zonk)
|
go honkworldwide(user, &zonk)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
|
_, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -853,7 +851,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
var convoy string
|
var convoy string
|
||||||
if rid != "" {
|
if rid != "" {
|
||||||
xonk := getxonk("", rid)
|
xonk := getxonk(userinfo.UserID, rid)
|
||||||
if xonk != nil {
|
if xonk != nil {
|
||||||
if xonk.Honker == "" {
|
if xonk.Honker == "" {
|
||||||
rid = "https://" + serverName + "/u/" + xonk.Username + "/h/" + rid
|
rid = "https://" + serverName + "/u/" + xonk.Username + "/h/" + rid
|
||||||
|
@ -1297,7 +1295,7 @@ var stmtHonksForUser, stmtHonksForMe, stmtSaveDub *sql.Stmt
|
||||||
var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
|
var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
|
||||||
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
|
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
|
||||||
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt
|
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt
|
||||||
var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtSaveZonker *sql.Stmt
|
var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt
|
||||||
var stmtGetBoxes, stmtSaveBoxes *sql.Stmt
|
var stmtGetBoxes, stmtSaveBoxes *sql.Stmt
|
||||||
|
|
||||||
func preparetodie(db *sql.DB, s string) *sql.Stmt {
|
func preparetodie(db *sql.DB, s string) *sql.Stmt {
|
||||||
|
@ -1319,7 +1317,7 @@ func prepareStatements(db *sql.DB) {
|
||||||
selecthonks := "select honkid, honks.userid, username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid "
|
selecthonks := "select honkid, honks.userid, username, what, honker, honks.xid, rid, dt, url, audience, noise, convoy from honks join users on honks.userid = users.userid "
|
||||||
limit := " order by honkid desc limit 250"
|
limit := " order by honkid desc limit 250"
|
||||||
butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)"
|
butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)"
|
||||||
stmtOneXonk = preparetodie(db, selecthonks+"where xid = ?")
|
stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")
|
||||||
stmtPublicHonks = preparetodie(db, selecthonks+"where honker = '' and dt > ?"+limit)
|
stmtPublicHonks = preparetodie(db, selecthonks+"where honker = '' and dt > ?"+limit)
|
||||||
stmtUserHonks = preparetodie(db, selecthonks+"where honker = '' and username = ? and dt > ?"+limit)
|
stmtUserHonks = preparetodie(db, selecthonks+"where honker = '' and username = ? and dt > ?"+limit)
|
||||||
stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ?"+butnotthose+limit)
|
stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ?"+butnotthose+limit)
|
||||||
|
@ -1333,6 +1331,7 @@ func prepareStatements(db *sql.DB) {
|
||||||
stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
|
stmtFindXonk = preparetodie(db, "select honkid from honks where userid = ? and xid = ?")
|
||||||
stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
|
stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
|
||||||
stmtZonkIt = preparetodie(db, "delete from honks where userid = ? and xid = ?")
|
stmtZonkIt = preparetodie(db, "delete from honks where userid = ? and xid = ?")
|
||||||
|
stmtZonkDonks = preparetodie(db, "delete from donks where honkid = ?")
|
||||||
stmtFindFile = preparetodie(db, "select fileid from files where url = ?")
|
stmtFindFile = preparetodie(db, "select fileid from files where url = ?")
|
||||||
stmtSaveFile = preparetodie(db, "insert into files (xid, name, url, media, content) values (?, ?, ?, ?, ?)")
|
stmtSaveFile = preparetodie(db, "insert into files (xid, name, url, media, content) values (?, ?, ?, ?, ?)")
|
||||||
stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey from users where username = ?")
|
stmtWhatAbout = preparetodie(db, "select userid, username, displayname, about, pubkey from users where username = ?")
|
||||||
|
|
Loading…
Reference in New Issue