less awkard use of xonkers table
This commit is contained in:
parent
156a4029a2
commit
f29f31d32c
19
activity.go
19
activity.go
|
@ -344,9 +344,9 @@ func getboxes(ident string) (*Box, error) {
|
|||
return b, nil
|
||||
}
|
||||
|
||||
row := stmtGetBoxes.QueryRow(ident)
|
||||
b = &Box{}
|
||||
err := row.Scan(&b.In, &b.Out, &b.Shared)
|
||||
var info string
|
||||
row := stmtGetXonker.QueryRow(ident, "boxes")
|
||||
err := row.Scan(&info)
|
||||
if err != nil {
|
||||
j, err := GetJunk(ident)
|
||||
if err != nil {
|
||||
|
@ -357,12 +357,17 @@ func getboxes(ident string) (*Box, error) {
|
|||
sbox, _ := jsonfindstring(j, []string{"endpoints", "sharedInbox"})
|
||||
b = &Box{In: inbox, Out: outbox, Shared: sbox}
|
||||
if inbox != "" {
|
||||
_, err = stmtSaveBoxes.Exec(ident, inbox, outbox, sbox, "")
|
||||
m := strings.Join([]string{inbox, outbox, sbox}, " ")
|
||||
_, err = stmtSaveXonker.Exec(ident, m, "boxes")
|
||||
if err != nil {
|
||||
log.Printf("error saving boxes: %s", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
m := strings.Split(info, " ")
|
||||
b = &Box{In: m[0], Out: m[1], Shared: m[2]}
|
||||
}
|
||||
|
||||
boxlock.Lock()
|
||||
boxofboxes[ident] = b
|
||||
boxlock.Unlock()
|
||||
|
@ -889,8 +894,7 @@ func gofish(name string) string {
|
|||
if ok {
|
||||
return ref
|
||||
}
|
||||
db := opendatabase()
|
||||
row := db.QueryRow("select ibox from xonkers where xid = ?", name)
|
||||
row := stmtGetXonker.QueryRow(name, "fishname")
|
||||
var href string
|
||||
err := row.Scan(&href)
|
||||
if err == nil {
|
||||
|
@ -914,8 +918,7 @@ func gofish(name string) string {
|
|||
rel, _ := jsongetstring(l, "rel")
|
||||
t, _ := jsongetstring(l, "type")
|
||||
if rel == "self" && friendorfoe(t) {
|
||||
db.Exec("insert into xonkers (xid, ibox, obox, sbox, pubkey) values (?, ?, ?, ?, ?)",
|
||||
name, href, "", "", "")
|
||||
stmtSaveXonker.Exec(name, href, "fishname")
|
||||
handlock.Lock()
|
||||
handfull[name] = href
|
||||
handlock.Unlock()
|
||||
|
|
5
fun.go
5
fun.go
|
@ -394,8 +394,7 @@ func zaggy(keyname string) (key *rsa.PublicKey) {
|
|||
if key != nil {
|
||||
return
|
||||
}
|
||||
db := opendatabase()
|
||||
row := db.QueryRow("select pubkey from xonkers where xid = ?", keyname)
|
||||
row := stmtGetXonker.QueryRow(keyname, "pubkey")
|
||||
var data string
|
||||
err := row.Scan(&data)
|
||||
if err != nil {
|
||||
|
@ -421,7 +420,7 @@ func zaggy(keyname string) (key *rsa.PublicKey) {
|
|||
log.Printf("error decoding %s pubkey: %s", keyname, err)
|
||||
return
|
||||
}
|
||||
_, err = stmtSaveBoxes.Exec(keyname, "", "", "", data)
|
||||
_, err = stmtSaveXonker.Exec(keyname, data, "pubkey")
|
||||
if err != nil {
|
||||
log.Printf("error saving key: %s", err)
|
||||
}
|
||||
|
|
6
honk.go
6
honk.go
|
@ -1354,7 +1354,7 @@ var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
|
|||
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
|
||||
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt
|
||||
var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt
|
||||
var stmtGetBoxes, stmtSaveBoxes *sql.Stmt
|
||||
var stmtGetXonker, stmtSaveXonker *sql.Stmt
|
||||
|
||||
func preparetodie(db *sql.DB, s string) *sql.Stmt {
|
||||
stmt, err := db.Prepare(s)
|
||||
|
@ -1400,8 +1400,8 @@ func prepareStatements(db *sql.DB) {
|
|||
stmtZapDoover = preparetodie(db, "delete from doovers where dooverid = ?")
|
||||
stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zurl' or wherefore = 'zword')")
|
||||
stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)")
|
||||
stmtGetBoxes = preparetodie(db, "select ibox, obox, sbox from xonkers where xid = ?")
|
||||
stmtSaveBoxes = preparetodie(db, "insert into xonkers (xid, ibox, obox, sbox, pubkey) values (?, ?, ?, ?, ?)")
|
||||
stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?")
|
||||
stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)")
|
||||
}
|
||||
|
||||
func ElaborateUnitTests() {
|
||||
|
|
|
@ -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 files(fileid integer primary key, xid text, name text, url text, media text, local integer, content blob);
|
||||
create table honkers (honkerid integer primary key, userid integer, name text, xid text, flavor text, combos text, pubkey text);
|
||||
create table xonkers (xonkerid integer primary key, xid text, ibox text, obox text, sbox text, pubkey text);
|
||||
create table xonkers (xonkerid integer primary key, name text, info text, flavor 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, username text, rcpt text, msg blob);
|
||||
|
||||
|
@ -11,7 +11,7 @@ create index idx_honksxid on honks(xid);
|
|||
create index idx_honksconvoy on honks(convoy);
|
||||
create index idx_honkshonker on honks(honker);
|
||||
create index idx_honkerxid on honkers(xid);
|
||||
create index idx_xonkerxid on xonkers(xid);
|
||||
create index idx_xonkername on xonkers(name);
|
||||
create index idx_zonkersname on zonkers(name);
|
||||
create index idx_filesxid on files(xid);
|
||||
create index idx_filesurl on files(url);
|
||||
|
|
|
@ -93,6 +93,11 @@ func upgradedb() {
|
|||
doordie(db, "update files set local = 1")
|
||||
doordie(db, "update config set value = 9 where key = 'dbversion'")
|
||||
case 9:
|
||||
doordie(db, "drop table xonkers")
|
||||
doordie(db, "create table xonkers (xonkerid integer primary key, name text, info text, flavor text)")
|
||||
doordie(db, "create index idx_xonkername on xonkers(name)")
|
||||
doordie(db, "update config set value = 10 where key = 'dbversion'")
|
||||
case 10:
|
||||
default:
|
||||
log.Fatalf("can't upgrade unknown version %d", dbversion)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue