From c20f7e7eff2c59a5b35263232c76d14c0cbd0297 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 29 Oct 2019 19:14:41 -0400 Subject: [PATCH] use a flag for the untagged honks --- database.go | 4 ++-- hfcs.go | 29 +++++++++++++++++------------ honk.go | 11 ++++++++--- web.go | 15 ++++++++++++--- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/database.go b/database.go index d1c2945..861a003 100644 --- a/database.go +++ b/database.go @@ -683,7 +683,7 @@ var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtUserByName, stmtUser 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 @@ func prepareStatements(db *sql.DB) { 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 (?, ?, ?)") diff --git a/hfcs.go b/hfcs.go index 5ae74e8..a34d82d 100644 --- a/hfcs.go +++ b/hfcs.go @@ -302,30 +302,35 @@ func unsee(userid int64, h *Honk) { } } -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 @@ func osmosis(honks []*Honk, userid int64, withfilt bool) []*Honk { honks[j] = h j++ } - desubbed.Unlock() + untagged.Unlock() honks = honks[0:j] reversehonks(honks) if !withfilt { diff --git a/honk.go b/honk.go index 80d984a..916ff0d 100644 --- a/honk.go +++ b/honk.go @@ -91,9 +91,10 @@ type OldRevision struct { } const ( - flagIsAcked = 1 - flagIsBonked = 2 - flagIsSaved = 4 + flagIsAcked = 1 + flagIsBonked = 2 + flagIsSaved = 4 + flagIsUntagged = 8 ) func (honk *Honk) IsAcked() bool { @@ -108,6 +109,10 @@ func (honk *Honk) IsSaved() bool { return honk.Flags&flagIsSaved != 0 } +func (honk *Honk) IsUntagged() bool { + return honk.Flags&flagIsUntagged != 0 +} + type Donk struct { FileID int64 XID string diff --git a/web.go b/web.go index d723820..2d40ac5 100644 --- a/web.go +++ b/web.go @@ -1107,6 +1107,18 @@ func zonkit(w http.ResponseWriter, r *http.Request) { 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) @@ -1122,9 +1134,6 @@ func zonkit(w http.ResponseWriter, r *http.Request) { log.Printf("error saving zonker: %s", err) return } - if wherefore == "desub" { - desubbed.Clear(userinfo.UserID) - } } func edithonkpage(w http.ResponseWriter, r *http.Request) {