M activity.go +7 -23
@@ 439,7 439,7 @@ var boxofboxes = gencache.New(gencache.O
return b, true
}
return nil, false
-}})
+}, Invalidator: &xonkInvalidator})
var gettergate = gate.NewLimiter(1)
@@ 1162,7 1162,7 @@ func xonksaver2(user *WhatAbout, item ju
m.Who, _ = tag.GetString("name")
m.Where, _ = tag.GetString("href")
if m.Who == "" {
- m.Where = m.Who
+ m.Who = m.Where
}
if m.Where != "" {
mentions = append(mentions, m)
@@ 1903,16 1903,12 @@ var handfull = gencache.New(gencache.Opt
rel, _ := l.GetString("rel")
t, _ := l.GetString("type")
if rel == "self" && friendorfoe(t) {
- when := time.Now().UTC().Format(dbtimeformat)
- _, err := stmtSaveXonker.Exec(name, href, "fishname", when)
- if err != nil {
- elog.Printf("error saving fishname: %s", err)
- }
+ savexonker(name, href, "fishname")
return href, true
}
}
return href, true
-}, Duration: 1 * time.Minute})
+}, Invalidator: &xonkInvalidator})
func gofish(name string) string {
if name[0] == '@' {
@@ 2012,11 2008,7 @@ func allinjest(origin string, obj junk.J
ingesthandle(origin, obj)
chatkey, ok := obj.GetString(chatKeyProp)
if ok {
- when := time.Now().UTC().Format(dbtimeformat)
- _, err := stmtSaveXonker.Exec(ident, chatkey, chatKeyProp, when)
- if err != nil {
- elog.Printf("error saving chatkey: %s", err)
- }
+ savexonker(ident, chatkey, chatKeyProp)
}
}
@@ 2082,12 2074,8 @@ func ingestboxes(origin string, obj junk
outbox, _ := obj.GetString("outbox")
sbox, _ := obj.GetString("endpoints", "sharedInbox")
if inbox != "" {
- when := time.Now().UTC().Format(dbtimeformat)
m := strings.Join([]string{inbox, outbox, sbox}, " ")
- _, err = stmtSaveXonker.Exec(ident, m, "boxes", when)
- if err != nil {
- elog.Printf("error saving boxes: %s", err)
- }
+ savexonker(ident, m, "boxes")
}
}
@@ 2107,11 2095,7 @@ func ingesthandle(origin string, obj jun
}
handle, _ = obj.GetString("preferredUsername")
if handle != "" {
- when := time.Now().UTC().Format(dbtimeformat)
- _, err = stmtSaveXonker.Exec(xid, handle, "handle", when)
- if err != nil {
- elog.Printf("error saving handle: %s", err)
- }
+ savexonker(xid, handle, "handle")
}
}
M database.go +7 -3
@@ 987,8 987,12 @@ func getxonker(what, flav string) string
return res
}
-func savexonker(what, value, flav, when string) {
- stmtSaveXonker.Exec(what, value, flav, when)
+func savexonker(what, value, flav string) {
+ when := time.Now().UTC().Format(dbtimeformat)
+ _, err := stmtSaveXonker.Exec(what, value, flav, when)
+ if err != nil {
+ elog.Printf("error saving xonker: %s", err)
+ }
}
func savehonker(user *WhatAbout, url, name, flavor, combos, mj string) (int64, string, error) {
@@ 1217,7 1221,7 @@ func prepareStatements(db *sql.DB) {
stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?")
stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor, dt) values (?, ?, ?, ?)")
stmtDeleteXonker = preparetodie(db, "delete from xonkers where name = ? and flavor = ? and dt < ?")
- stmtDeleteOldXonkers = preparetodie(db, "delete from xonkers where flavor = ? and dt < ?")
+ stmtDeleteOldXonkers = preparetodie(db, "delete from xonkers where dt < ?")
stmtRecentHonkers = preparetodie(db, "select distinct(honker) from honks where userid = ? and honker not in (select xid from honkers where userid = ? and flavor = 'sub') order by honkid desc limit 100")
stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where honkid = ?")
stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where honkid = ?")
M encrypt.go +2 -5
@@ 22,7 22,6 @@ import (
"fmt"
"io"
"strings"
- "time"
"golang.org/x/crypto/nacl/box"
"humungus.tedunangst.com/r/webs/gencache"
@@ 104,16 103,14 @@ var chatkeys = gencache.New(gencache.Opt
j, err := GetJunk(readyLuserOne, xonker)
if err != nil {
ilog.Printf("error getting %s: %s", xonker, err)
- when := time.Now().UTC().Format(dbtimeformat)
- stmtSaveXonker.Exec(xonker, "failed", chatKeyProp, when)
+ savexonker(xonker, "failed", chatKeyProp)
return boxPubKey{}, true
}
allinjest(originate(xonker), j)
data = getxonker(xonker, chatKeyProp)
if data == "" {
ilog.Printf("key not found after ingesting")
- when := time.Now().UTC().Format(dbtimeformat)
- stmtSaveXonker.Exec(xonker, "failed", chatKeyProp, when)
+ savexonker(xonker, "failed", chatKeyProp)
return boxPubKey{}, true
}
}
M fun.go +7 -8
@@ 633,6 633,8 @@ func originate(u string) string {
return ""
}
+var xonkInvalidator gencache.Invalidator[string]
+
var allhandles = gencache.New(gencache.Options[string, string]{Fill: func(xid string) (string, bool) {
handle := getxonker(xid, "handle")
if handle == "" {
@@ 646,14 648,13 @@ var allhandles = gencache.New(gencache.O
} else {
handle = xid
}
- when := time.Now().UTC().Format(dbtimeformat)
- savexonker(xid, handle, "handle", when)
+ savexonker(xid, handle, "handle")
} else {
handle = info.Name
}
}
return handle, true
-}})
+}, Invalidator: &xonkInvalidator})
// handle, handle@host
func handles(xid string) (string, string) {
@@ 730,16 731,14 @@ var zaggies = gencache.New(gencache.Opti
j, err := GetJunk(readyLuserOne, keyname)
if err != nil {
ilog.Printf("error getting %s pubkey: %s", keyname, err)
- when := time.Now().UTC().Format(dbtimeformat)
- stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
+ savexonker(keyname, "failed", "pubkey")
return httpsig.PublicKey{}, true
}
allinjest(originate(keyname), j)
data = getxonker(keyname, "pubkey")
if data == "" {
ilog.Printf("key not found after ingesting")
- when := time.Now().UTC().Format(dbtimeformat)
- stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
+ savexonker(keyname, "failed", "pubkey")
return httpsig.PublicKey{}, true
}
}
@@ 753,7 752,7 @@ var zaggies = gencache.New(gencache.Opti
return key, true
}
return key, true
-}, Limit: 512})
+}, Limit: 4096, Invalidator: &xonkInvalidator})
func zaggy(keyname string) (httpsig.PublicKey, error) {
key, _ := zaggies.Get(keyname)
M import.go +3 -5
@@ 21,7 21,6 @@ import (
"encoding/json"
"fmt"
"html"
- "io/ioutil"
"log"
"os"
"regexp"
@@ 208,7 207,7 @@ func importActivities(user *WhatAbout, f
switch att.Type {
case "Document":
fname := fmt.Sprintf("%s/%s", source, att.Url)
- data, err := ioutil.ReadFile(fname)
+ data, err := os.ReadFile(fname)
if err != nil {
elog.Printf("error reading media for %s: %s", honk.XID, fname)
continue
@@ 465,7 464,7 @@ func importTwitter(username, source stri
idx := strings.LastIndexByte(u, '/')
u = u[idx+1:]
fname := fmt.Sprintf("%s/tweet_media/%s-%s", source, t.Tweet.IdStr, u)
- data, err := ioutil.ReadFile(fname)
+ data, err := os.ReadFile(fname)
if err != nil {
elog.Printf("error reading media: %s", fname)
continue
@@ 546,7 545,7 @@ func importInstagram(username, source st
var meta DonkMeta
u := xfiltrate()
fname := fmt.Sprintf("%s/%s", source, g.URI)
- data, err := ioutil.ReadFile(fname)
+ data, err := os.ReadFile(fname)
if err != nil {
elog.Printf("error reading media: %s", fname)
continue
@@ 642,7 641,6 @@ func export(username, file string) {
if donk == "" {
continue
}
- var data []byte
w, err := zd.Create("media/" + donk)
if err != nil {
elog.Printf("error creating %s: %s", donk, err)
M web.go +4 -4
@@ 3103,13 3103,13 @@ func enditall() {
func bgmonitor() {
for {
- when := time.Now().Add(-3 * 24 * time.Hour).UTC().Format(dbtimeformat)
- _, err := stmtDeleteOldXonkers.Exec("pubkey", when)
+ when := time.Now().Add(-2 * 24 * time.Hour).UTC().Format(dbtimeformat)
+ _, err := stmtDeleteOldXonkers.Exec(when)
if err != nil {
elog.Printf("error deleting old xonkers: %s", err)
}
- zaggies.Flush()
- time.Sleep(50 * time.Minute)
+ xonkInvalidator.Flush()
+ time.Sleep(150 * time.Minute)
}
}