diff --git a/activity.go b/activity.go index c152eaa..0ed6f02 100644 --- a/activity.go +++ b/activity.go @@ -1317,7 +1317,8 @@ var handfull = cache.New(cache.Options{Filler: func(name string) (string, bool) rel, _ := l.GetString("rel") t, _ := l.GetString("type") if rel == "self" && friendorfoe(t) { - _, err := stmtSaveXonker.Exec(name, href, "fishname") + when := time.Now().UTC().Format(dbtimeformat) + _, err := stmtSaveXonker.Exec(name, href, "fishname", when) if err != nil { log.Printf("error saving fishname: %s", err) } @@ -1430,7 +1431,8 @@ func ingestpubkey(origin string, obj junk.Junk) { log.Printf("error decoding %s pubkey: %s", keyname, err) return } - _, err = stmtSaveXonker.Exec(keyname, data, "pubkey") + when := time.Now().UTC().Format(dbtimeformat) + _, err = stmtSaveXonker.Exec(keyname, data, "pubkey", when) if err != nil { log.Printf("error saving key: %s", err) } @@ -1455,8 +1457,9 @@ func ingestboxes(origin string, obj junk.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") + _, err = stmtSaveXonker.Exec(ident, m, "boxes", when) if err != nil { log.Printf("error saving boxes: %s", err) } @@ -1479,7 +1482,8 @@ func ingesthandle(origin string, obj junk.Junk) { } handle, _ = obj.GetString("preferredUsername") if handle != "" { - _, err = stmtSaveXonker.Exec(xid, handle, "handle") + when := time.Now().UTC().Format(dbtimeformat) + _, err = stmtSaveXonker.Exec(xid, handle, "handle", when) if err != nil { log.Printf("error saving handle: %s", err) } diff --git a/database.go b/database.go index 2402a46..1af843c 100644 --- a/database.go +++ b/database.go @@ -760,8 +760,8 @@ func prepareStatements(db *sql.DB) { stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?") - stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)") - stmtDeleteXonker = preparetodie(db, "delete 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 < ?") 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 = ?") diff --git a/schema.go b/schema.go index a78fb24..82464e7 100644 --- a/schema.go +++ b/schema.go @@ -6,7 +6,7 @@ create table honks (honkid integer primary key, userid integer, what text, honke create table donks (honkid integer, fileid integer); create table filemeta (fileid integer primary key, xid text, name text, description text, url text, media text, local integer); create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, owner text); -create table xonkers (xonkerid integer primary key, name text, info text, flavor text); +create table xonkers (xonkerid integer primary key, name text, info text, flavor text, dt text); create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text); create table doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob); create table onts (ontology text, honkid integer); diff --git a/schema.sql b/schema.sql index 0587f73..db02483 100644 --- a/schema.sql +++ b/schema.sql @@ -3,7 +3,7 @@ create table honks (honkid integer primary key, userid integer, what text, honke create table donks (honkid integer, fileid integer); create table filemeta (fileid integer primary key, xid text, name text, description text, url text, media text, local integer); create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, owner text); -create table xonkers (xonkerid integer primary key, name text, info text, flavor text); +create table xonkers (xonkerid integer primary key, name text, info text, flavor text, dt text); create table zonkers (zonkerid integer primary key, userid integer, name text, wherefore text); create table doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob); create table onts (ontology text, honkid integer); diff --git a/upgradedb.go b/upgradedb.go index 828349a..3c968b9 100644 --- a/upgradedb.go +++ b/upgradedb.go @@ -24,7 +24,7 @@ import ( "time" ) -var myVersion = 32 +var myVersion = 33 func doordie(db *sql.DB, s string, args ...interface{}) { _, err := db.Exec(s, args...) @@ -356,6 +356,11 @@ func upgradedb() { doordie(db, "update config set value = 32 where key = 'dbversion'") fallthrough case 32: + doordie(db, "alter table xonkers add column dt text") + doordie(db, "update xonkers set dt = ?", time.Now().UTC().Format(dbtimeformat)) + doordie(db, "update config set value = 33 where key = 'dbversion'") + fallthrough + case 33: default: log.Fatalf("can't upgrade unknown version %d", dbversion)