use a flag for the untagged honks

This commit is contained in:
Ted Unangst 2019-10-29 19:14:41 -04:00
parent 209a7f0b4f
commit c20f7e7eff
4 changed files with 39 additions and 20 deletions

View File

@ -683,7 +683,7 @@ var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtUserByName, stmtUser
var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt
var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *sql.Stmt
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover, stmtOneHonker *sql.Stmt
var stmtDesubbed, 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, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *sql.Stmt
@ -749,7 +749,7 @@ func prepareStatements(db *sql.DB) {
stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers") stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers")
stmtLoadDoover = preparetodie(db, "select tries, userid, rcpt, msg from doovers where dooverid = ?") stmtLoadDoover = preparetodie(db, "select tries, userid, rcpt, msg from doovers where dooverid = ?")
stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?") stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?")
stmtDesubbed = preparetodie(db, "select name from zonkers where userid = ? and wherefore = 'desub'") stmtUntagged = preparetodie(db, "select xid, rid, flags from (select honkid, xid, rid, flags from honks where userid = ? order by honkid desc limit 2000) order by honkid asc")
stmtFindZonk = preparetodie(db, "select zonkerid from zonkers where userid = ? and name = ? and wherefore = 'zonk'") 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'") stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'")
stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)")

29
hfcs.go
View File

@ -302,30 +302,35 @@ func unsee(userid int64, h *Honk) {
} }
} }
var desubbed = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) { var untagged = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) {
rows, err := stmtDesubbed.Query(userid) rows, err := stmtUntagged.Query(userid)
if err != nil { if err != nil {
log.Printf("error query desubbed: %s", err) log.Printf("error query untagged: %s", err)
return nil, false return nil, false
} }
defer rows.Close() defer rows.Close()
m := make(map[string]bool) bad := make(map[string]bool)
for rows.Next() { for rows.Next() {
var xid string var xid, rid string
err = rows.Scan(&xid) var flags int64
err = rows.Scan(&xid, &rid, &flags)
if err != nil { if err != nil {
log.Printf("error scanning desub: %s", err) log.Printf("error scanning untag: %s", err)
continue continue
} }
log.Printf("bad parent: %s", xid) if flags&flagIsUntagged != 0 {
m[xid] = true bad[xid] = true
}
if bad[rid] {
bad[xid] = true
}
} }
return m, true return bad, true
}}) }})
func osmosis(honks []*Honk, userid int64, withfilt bool) []*Honk { func osmosis(honks []*Honk, userid int64, withfilt bool) []*Honk {
var badparents map[string]bool var badparents map[string]bool
desubbed.GetAndLock(userid, &badparents) untagged.GetAndLock(userid, &badparents)
j := 0 j := 0
reversehonks(honks) reversehonks(honks)
for _, h := range honks { for _, h := range honks {
@ -336,7 +341,7 @@ func osmosis(honks []*Honk, userid int64, withfilt bool) []*Honk {
honks[j] = h honks[j] = h
j++ j++
} }
desubbed.Unlock() untagged.Unlock()
honks = honks[0:j] honks = honks[0:j]
reversehonks(honks) reversehonks(honks)
if !withfilt { if !withfilt {

11
honk.go
View File

@ -91,9 +91,10 @@ type OldRevision struct {
} }
const ( const (
flagIsAcked = 1 flagIsAcked = 1
flagIsBonked = 2 flagIsBonked = 2
flagIsSaved = 4 flagIsSaved = 4
flagIsUntagged = 8
) )
func (honk *Honk) IsAcked() bool { func (honk *Honk) IsAcked() bool {
@ -108,6 +109,10 @@ func (honk *Honk) IsSaved() bool {
return honk.Flags&flagIsSaved != 0 return honk.Flags&flagIsSaved != 0
} }
func (honk *Honk) IsUntagged() bool {
return honk.Flags&flagIsUntagged != 0
}
type Donk struct { type Donk struct {
FileID int64 FileID int64
XID string XID string

15
web.go
View File

@ -1107,6 +1107,18 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
return return
} }
if wherefore == "untag" {
xonk := getxonk(userinfo.UserID, what)
if xonk != nil {
_, err := stmtUpdateFlags.Exec(flagIsUntagged, xonk.ID)
if err != nil {
log.Printf("error untagging: %s", err)
}
}
untagged.Clear(userinfo.UserID)
return
}
log.Printf("zonking %s %s", wherefore, what) log.Printf("zonking %s %s", wherefore, what)
if wherefore == "zonk" { if wherefore == "zonk" {
xonk := getxonk(userinfo.UserID, what) xonk := getxonk(userinfo.UserID, what)
@ -1122,9 +1134,6 @@ func zonkit(w http.ResponseWriter, r *http.Request) {
log.Printf("error saving zonker: %s", err) log.Printf("error saving zonker: %s", err)
return return
} }
if wherefore == "desub" {
desubbed.Clear(userinfo.UserID)
}
} }
func edithonkpage(w http.ResponseWriter, r *http.Request) { func edithonkpage(w http.ResponseWriter, r *http.Request) {