save timestamp for xonker additions

This commit is contained in:
Ted Unangst 2019-11-25 15:50:17 -05:00
parent 9539ce5df6
commit c9aba7ecba
5 changed files with 18 additions and 9 deletions

View File

@ -1317,7 +1317,8 @@ var handfull = cache.New(cache.Options{Filler: func(name string) (string, bool)
rel, _ := l.GetString("rel") rel, _ := l.GetString("rel")
t, _ := l.GetString("type") t, _ := l.GetString("type")
if rel == "self" && friendorfoe(t) { 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 { if err != nil {
log.Printf("error saving fishname: %s", err) 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) log.Printf("error decoding %s pubkey: %s", keyname, err)
return return
} }
_, err = stmtSaveXonker.Exec(keyname, data, "pubkey") when := time.Now().UTC().Format(dbtimeformat)
_, err = stmtSaveXonker.Exec(keyname, data, "pubkey", when)
if err != nil { if err != nil {
log.Printf("error saving key: %s", err) log.Printf("error saving key: %s", err)
} }
@ -1455,8 +1457,9 @@ func ingestboxes(origin string, obj junk.Junk) {
outbox, _ := obj.GetString("outbox") outbox, _ := obj.GetString("outbox")
sbox, _ := obj.GetString("endpoints", "sharedInbox") sbox, _ := obj.GetString("endpoints", "sharedInbox")
if inbox != "" { if inbox != "" {
when := time.Now().UTC().Format(dbtimeformat)
m := strings.Join([]string{inbox, outbox, sbox}, " ") m := strings.Join([]string{inbox, outbox, sbox}, " ")
_, err = stmtSaveXonker.Exec(ident, m, "boxes") _, err = stmtSaveXonker.Exec(ident, m, "boxes", when)
if err != nil { if err != nil {
log.Printf("error saving boxes: %s", err) log.Printf("error saving boxes: %s", err)
} }
@ -1479,7 +1482,8 @@ func ingesthandle(origin string, obj junk.Junk) {
} }
handle, _ = obj.GetString("preferredUsername") handle, _ = obj.GetString("preferredUsername")
if handle != "" { if handle != "" {
_, err = stmtSaveXonker.Exec(xid, handle, "handle") when := time.Now().UTC().Format(dbtimeformat)
_, err = stmtSaveXonker.Exec(xid, handle, "handle", when)
if err != nil { if err != nil {
log.Printf("error saving handle: %s", err) log.Printf("error saving handle: %s", err)
} }

View File

@ -760,8 +760,8 @@ func prepareStatements(db *sql.DB) {
stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'") stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ? and wherefore <> 'zonk'")
stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)")
stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?") stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?")
stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)") stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor, dt) values (?, ?, ?, ?)")
stmtDeleteXonker = preparetodie(db, "delete from xonkers where name = ? and flavor = ?") 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") 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 = ?") stmtUpdateFlags = preparetodie(db, "update honks set flags = flags | ? where honkid = ?")
stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where honkid = ?") stmtClearFlags = preparetodie(db, "update honks set flags = flags & ~ ? where honkid = ?")

View File

@ -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 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 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 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 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 doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob);
create table onts (ontology text, honkid integer); create table onts (ontology text, honkid integer);

View File

@ -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 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 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 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 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 doovers(dooverid integer primary key, dt text, tries integer, userid integer, rcpt text, msg blob);
create table onts (ontology text, honkid integer); create table onts (ontology text, honkid integer);

View File

@ -24,7 +24,7 @@ import (
"time" "time"
) )
var myVersion = 32 var myVersion = 33
func doordie(db *sql.DB, s string, args ...interface{}) { func doordie(db *sql.DB, s string, args ...interface{}) {
_, err := db.Exec(s, args...) _, err := db.Exec(s, args...)
@ -356,6 +356,11 @@ func upgradedb() {
doordie(db, "update config set value = 32 where key = 'dbversion'") doordie(db, "update config set value = 32 where key = 'dbversion'")
fallthrough fallthrough
case 32: 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: default:
log.Fatalf("can't upgrade unknown version %d", dbversion) log.Fatalf("can't upgrade unknown version %d", dbversion)