all repos — honk @ 2b081dc63590ac40e5cce10dd5a69cfe889f3bbf

my fork of honk

when sending updates or deletes, send to all fetch recipients too
Ted Unangst tedu@tedunangst.com
Tue, 26 Nov 2019 00:29:31 -0500
commit

2b081dc63590ac40e5cce10dd5a69cfe889f3bbf

parent

fb9695ebc3dff7aacc1681e932d98cb300f4f0eb

3 files changed, 38 insertions(+), 0 deletions(-)

jump to
M activity.goactivity.go

@@ -1209,6 +1209,9 @@ } else {

rcpts[h.XID] = true } } + for _, f := range getbacktracks(honk.XID) { + rcpts[f] = true + } } for a := range rcpts { go deliverate(0, user.ID, a, msg)
M database.godatabase.go

@@ -693,6 +693,7 @@ var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker, stmtDeleteXonker *sql.Stmt

var stmtAllOnts, stmtSaveOnt, stmtUpdateFlags, stmtClearFlags *sql.Stmt var stmtHonksForUserFirstClass, stmtSaveMeta, stmtDeleteMeta, stmtUpdateHonk *sql.Stmt var stmtHonksISaved, stmtGetFilters, stmtSaveFilter, stmtDeleteFilter *sql.Stmt +var stmtGetTracks *sql.Stmt func preparetodie(db *sql.DB, s string) *sql.Stmt { stmt, err := db.Prepare(s)

@@ -769,4 +770,5 @@ stmtAllOnts = preparetodie(db, "select ontology, count(ontology) from onts join honks on onts.honkid = honks.honkid where (honks.userid = ? or honks.whofore = 2) group by ontology")

stmtGetFilters = preparetodie(db, "select hfcsid, json from hfcs where userid = ?") stmtSaveFilter = preparetodie(db, "insert into hfcs (userid, json) values (?, ?)") stmtDeleteFilter = preparetodie(db, "delete from hfcs where userid = ? and hfcsid = ?") + stmtGetTracks = preparetodie(db, "select fetches from tracks where xid = ?") }
M web.goweb.go

@@ -890,6 +890,33 @@ xid string

who string } +func getbacktracks(xid string) []string { + c := make(chan bool) + dumptracks <- c + <-c + row := stmtGetTracks.QueryRow(xid) + var rawtracks string + err := row.Scan(&rawtracks) + if err != nil { + if err != sql.ErrNoRows { + log.Printf("error scanning tracks: %s", err) + } + return nil + } + var rcpts []string + for _, f := range strings.Split(rawtracks, " ") { + idx := strings.LastIndexByte(f, '#') + if idx != -1 { + f = f[:idx] + } + if !strings.HasPrefix(f, "https://") { + f = fmt.Sprintf("%https://%s/inbox", f) + } + rcpts = append(rcpts, f) + } + return rcpts +} + func savetracks(tracks map[string][]string) { db := opendatabase() tx, err := db.Begin()

@@ -940,6 +967,7 @@ log.Printf("saved %d new fetches", count)

} var trackchan = make(chan Track) +var dumptracks = make(chan chan bool) func tracker() { timeout := 4 * time.Minute

@@ -955,6 +983,11 @@ go savetracks(tracks)

tracks = make(map[string][]string) } sleeper.Reset(timeout) + case c := <-dumptracks: + if len(tracks) > 0 { + savetracks(tracks) + } + c <- true case <-endoftheworld: if len(tracks) > 0 { savetracks(tracks)