don't fetch bonks if we already have them
Ted Unangst tedu@tedunangst.com
Thu, 25 Apr 2019 01:18:39 -0400
2 files changed,
18 insertions(+),
8 deletions(-)
M
activity.go
→
activity.go
@@ -227,14 +227,21 @@ return &donk
} func needxonk(user *WhatAbout, x *Honk) bool { - if strings.HasPrefix(x.XID, user.URL+"/h/") { + if x == nil { return false } if x.What == "eradicate" { return true } - row := stmtFindXonk.QueryRow(user.ID, x.XID) - err := row.Scan(&x.ID) + return needxonkid(user, x.XID) +} +func needxonkid(user *WhatAbout, xid string) bool { + if strings.HasPrefix(xid, user.URL+"/h/") { + return false + } + row := stmtFindXonk.QueryRow(user.ID, xid) + var id int64 + err := row.Scan(&id) if err == nil { return false }@@ -361,8 +368,8 @@ items, _ = jsongetarray(j, "orderedItems")
} for _, item := range items { - xonk := xonkxonk(item) - if xonk != nil && needxonk(user, xonk) { + xonk := xonkxonk(user, item) + if needxonk(user, xonk) { xonk.UserID = user.ID savexonk(user, xonk) }@@ -401,7 +408,7 @@ }
return a } -func xonkxonk(item interface{}) *Honk { +func xonkxonk(user *WhatAbout, item interface{}) *Honk { // id, _ := jsongetstring(item, "id") what, _ := jsongetstring(item, "type") dt, _ := jsongetstring(item, "published")@@ -415,6 +422,9 @@ switch what {
case "Announce": xid, ok = jsongetstring(item, "object") if ok { + if !needxonkid(user, xid) { + return nil + } log.Printf("getting bonk: %s", xid) obj, err = GetJunk(xid) if err != nil {