don't fetch bonks if we already have them

This commit is contained in:
Ted Unangst 2019-04-25 01:18:39 -04:00
parent 4441d906f6
commit bf634b8224
2 changed files with 18 additions and 8 deletions

View File

@ -227,14 +227,21 @@ func savedonk(url string, name, media string) *Donk {
} }
func needxonk(user *WhatAbout, x *Honk) bool { func needxonk(user *WhatAbout, x *Honk) bool {
if strings.HasPrefix(x.XID, user.URL+"/h/") { if x == nil {
return false return false
} }
if x.What == "eradicate" { if x.What == "eradicate" {
return true return true
} }
row := stmtFindXonk.QueryRow(user.ID, x.XID) return needxonkid(user, x.XID)
err := row.Scan(&x.ID) }
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 { if err == nil {
return false return false
} }
@ -361,8 +368,8 @@ func peeppeep() {
} }
for _, item := range items { for _, item := range items {
xonk := xonkxonk(item) xonk := xonkxonk(user, item)
if xonk != nil && needxonk(user, xonk) { if needxonk(user, xonk) {
xonk.UserID = user.ID xonk.UserID = user.ID
savexonk(user, xonk) savexonk(user, xonk)
} }
@ -401,7 +408,7 @@ func newphone(a []string, obj map[string]interface{}) []string {
return a return a
} }
func xonkxonk(item interface{}) *Honk { func xonkxonk(user *WhatAbout, item interface{}) *Honk {
// id, _ := jsongetstring(item, "id") // id, _ := jsongetstring(item, "id")
what, _ := jsongetstring(item, "type") what, _ := jsongetstring(item, "type")
dt, _ := jsongetstring(item, "published") dt, _ := jsongetstring(item, "published")
@ -415,6 +422,9 @@ func xonkxonk(item interface{}) *Honk {
case "Announce": case "Announce":
xid, ok = jsongetstring(item, "object") xid, ok = jsongetstring(item, "object")
if ok { if ok {
if !needxonkid(user, xid) {
return nil
}
log.Printf("getting bonk: %s", xid) log.Printf("getting bonk: %s", xid)
obj, err = GetJunk(xid) obj, err = GetJunk(xid)
if err != nil { if err != nil {

View File

@ -365,8 +365,8 @@ func inbox(w http.ResponseWriter, r *http.Request) {
} }
} }
default: default:
xonk := xonkxonk(j) xonk := xonkxonk(user, j)
if xonk != nil && needxonk(user, xonk) { if needxonk(user, xonk) {
xonk.UserID = user.ID xonk.UserID = user.ID
savexonk(user, xonk) savexonk(user, xonk)
} }