diff --git a/database.go b/database.go index 4b22156..20b69de 100644 --- a/database.go +++ b/database.go @@ -680,7 +680,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 stmtThumbBiters, stmtDeleteHonk, stmtDeleteDonks, stmtDeleteOnts, stmtSaveZonker *sql.Stmt +var stmtDesubbed, 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 @@ -746,7 +746,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 = ?") - stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers") + stmtDesubbed = preparetodie(db, "select name from zonkers where userid = ? and wherefore = 'desub'") 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/go.mod b/go.mod index 8a0c705..481f4f0 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4 golang.org/x/net v0.0.0-20190620200207-3b0461eec859 humungus.tedunangst.com/r/go-sqlite3 v1.1.3 - humungus.tedunangst.com/r/webs v0.6.19 + humungus.tedunangst.com/r/webs v0.6.20 ) go 1.11 diff --git a/go.sum b/go.sum index 7d5152c..5472890 100644 --- a/go.sum +++ b/go.sum @@ -36,3 +36,5 @@ humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9 humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= humungus.tedunangst.com/r/webs v0.6.19 h1:0cxR4JmHDMQmMwboRlycRO+67OPtgtCwLX8fuDu9IRo= humungus.tedunangst.com/r/webs v0.6.19/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= +humungus.tedunangst.com/r/webs v0.6.20 h1:fKTjJ+EQUlxj8vWBtFMhX7aYbMwAnUWbDhY7hotkXq0= +humungus.tedunangst.com/r/webs v0.6.20/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps= diff --git a/hfcs.go b/hfcs.go index e21233d..5ae74e8 100644 --- a/hfcs.go +++ b/hfcs.go @@ -302,9 +302,48 @@ func unsee(userid int64, h *Honk) { } } -func osmosis(honks []*Honk, userid int64) []*Honk { - filts := getfilters(userid, filtHide) +var desubbed = cache.New(cache.Options{Filler: func(userid int64) (map[string]bool, bool) { + rows, err := stmtDesubbed.Query(userid) + if err != nil { + log.Printf("error query desubbed: %s", err) + return nil, false + } + defer rows.Close() + m := make(map[string]bool) + for rows.Next() { + var xid string + err = rows.Scan(&xid) + if err != nil { + log.Printf("error scanning desub: %s", err) + continue + } + log.Printf("bad parent: %s", xid) + m[xid] = true + } + return m, true +}}) + +func osmosis(honks []*Honk, userid int64, withfilt bool) []*Honk { + var badparents map[string]bool + desubbed.GetAndLock(userid, &badparents) j := 0 + reversehonks(honks) + for _, h := range honks { + if badparents[h.RID] { + badparents[h.XID] = true + continue + } + honks[j] = h + j++ + } + desubbed.Unlock() + honks = honks[0:j] + reversehonks(honks) + if !withfilt { + return honks + } + filts := getfilters(userid, filtHide) + j = 0 outer: for _, h := range honks { for _, f := range filts { diff --git a/views/honk.html b/views/honk.html index 838f3f9..01bf354 100644 --- a/views/honk.html +++ b/views/honk.html @@ -112,6 +112,7 @@ in reply to: {{ .RID }} {{ else }} {{ end }} + diff --git a/web.go b/web.go index 6b0563c..ba289b3 100644 --- a/web.go +++ b/web.go @@ -101,15 +101,16 @@ func homepage(w http.ResponseWriter, r *http.Request) { templinfo["ServerMessage"] = "at me!" templinfo["PageName"] = "atme" honks = gethonksforme(userid, 0) + honks = osmosis(honks, userid, false) case "/events": templinfo["ServerMessage"] = "some recent and upcoming events" templinfo["PageName"] = "events" honks = geteventhonks(userid) - honks = osmosis(honks, userid) + honks = osmosis(honks, userid, true) case "/first": templinfo["PageName"] = "first" honks = gethonksforuser(userid, 0) - honks = osmosis(honks, userid) + honks = osmosis(honks, userid, true) case "/saved": templinfo["ServerMessage"] = "saved honks" templinfo["PageName"] = "saved" @@ -117,7 +118,7 @@ func homepage(w http.ResponseWriter, r *http.Request) { default: templinfo["PageName"] = "home" honks = gethonksforuser(userid, 0) - honks = osmosis(honks, userid) + honks = osmosis(honks, userid, true) } templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) } @@ -723,7 +724,7 @@ func showcombo(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] u := login.GetUserInfo(r) honks := gethonksbycombo(u.UserID, name, 0) - honks = osmosis(honks, u.UserID) + honks = osmosis(honks, u.UserID, true) templinfo := getInfo(r) templinfo["PageName"] = "combo" templinfo["PageArg"] = name @@ -739,6 +740,7 @@ func showconvoy(w http.ResponseWriter, r *http.Request) { if len(honks) > 0 { templinfo["TopHID"] = honks[0].ID } + honks = osmosis(honks, u.UserID, false) reversehonks(honks) templinfo["PageName"] = "convoy" templinfo["PageArg"] = c @@ -1822,14 +1824,15 @@ func webhydra(w http.ResponseWriter, r *http.Request) { switch page { case "atme": honks = gethonksforme(userid, wanted) + honks = osmosis(honks, userid, false) templinfo["ServerMessage"] = "at me!" case "home": honks = gethonksforuser(userid, wanted) - honks = osmosis(honks, userid) + honks = osmosis(honks, userid, true) templinfo["ServerMessage"] = serverMsg case "first": honks = gethonksforuserfirstclass(userid, wanted) - honks = osmosis(honks, userid) + honks = osmosis(honks, userid, true) templinfo["ServerMessage"] = "first class only" case "saved": honks = getsavedhonks(userid, wanted) @@ -1838,11 +1841,12 @@ func webhydra(w http.ResponseWriter, r *http.Request) { case "combo": c := r.FormValue("c") honks = gethonksbycombo(userid, c, wanted) - honks = osmosis(honks, userid) + honks = osmosis(honks, userid, false) templinfo["ServerMessage"] = "honks by combo: " + c case "convoy": c := r.FormValue("c") honks = gethonksbyconvoy(userid, c, wanted) + honks = osmosis(honks, userid, false) templinfo["ServerMessage"] = "honks in convoy: " + c case "honker": xid := r.FormValue("xid")