use a flag for the untagged honks
Ted Unangst tedu@tedunangst.com
Tue, 29 Oct 2019 19:14:41 -0400
4 files changed,
39 insertions(+),
20 deletions(-)
M
database.go
→
database.go
@@ -683,7 +683,7 @@ var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtUserByName, stmtUserByNumber *sql.Stmt
var stmtEventHonks, stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt var stmtFindFile, stmtGetFileData, stmtSaveFileData, stmtSaveFile *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 stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtHonksForUserFirstClass, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *sql.Stmt@@ -749,7 +749,7 @@ stmtAddDoover = preparetodie(db, "insert into doovers (dt, tries, userid, rcpt, msg) values (?, ?, ?, ?, ?)")
stmtGetDoovers = preparetodie(db, "select dooverid, dt from doovers") stmtLoadDoover = preparetodie(db, "select tries, userid, rcpt, msg 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'") stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)")
M
hfcs.go
→
hfcs.go
@@ -302,30 +302,35 @@ }
} } -var desubbed = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) { - rows, err := stmtDesubbed.Query(userid) +var untagged = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) { + rows, err := stmtUntagged.Query(userid) if err != nil { - log.Printf("error query desubbed: %s", err) + log.Printf("error query untagged: %s", err) return nil, false } defer rows.Close() - m := make(map[string]bool) + bad := make(map[string]bool) for rows.Next() { - var xid string - err = rows.Scan(&xid) + var xid, rid string + var flags int64 + err = rows.Scan(&xid, &rid, &flags) if err != nil { - log.Printf("error scanning desub: %s", err) + log.Printf("error scanning untag: %s", err) continue } - log.Printf("bad parent: %s", xid) - m[xid] = true + if flags&flagIsUntagged != 0 { + bad[xid] = true + } + if bad[rid] { + bad[xid] = true + } } - return m, true + return bad, true }}) func osmosis(honks []*Honk, userid int64, withfilt bool) []*Honk { var badparents map[string]bool - desubbed.GetAndLock(userid, &badparents) + untagged.GetAndLock(userid, &badparents) j := 0 reversehonks(honks) for _, h := range honks {@@ -336,7 +341,7 @@ }
honks[j] = h j++ } - desubbed.Unlock() + untagged.Unlock() honks = honks[0:j] reversehonks(honks) if !withfilt {
M
honk.go
→
honk.go
@@ -91,9 +91,10 @@ Noise string
} const ( - flagIsAcked = 1 - flagIsBonked = 2 - flagIsSaved = 4 + flagIsAcked = 1 + flagIsBonked = 2 + flagIsSaved = 4 + flagIsUntagged = 8 ) func (honk *Honk) IsAcked() bool {@@ -106,6 +107,10 @@ }
func (honk *Honk) IsSaved() bool { return honk.Flags&flagIsSaved != 0 +} + +func (honk *Honk) IsUntagged() bool { + return honk.Flags&flagIsUntagged != 0 } type Donk struct {
M
web.go
→
web.go
@@ -1107,6 +1107,18 @@ }
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) if wherefore == "zonk" { xonk := getxonk(userinfo.UserID, what)@@ -1121,9 +1133,6 @@ _, err := stmtSaveZonker.Exec(userinfo.UserID, what, wherefore)
if err != nil { log.Printf("error saving zonker: %s", err) return - } - if wherefore == "desub" { - desubbed.Clear(userinfo.UserID) } }