all repos — honk @ de67e6459932911e4251f38202727ee5e8da3369

my fork of honk

less awkard use of xonkers table
Ted Unangst tedu@tedunangst.com
Mon, 03 Jun 2019 00:15:06 -0400
commit

de67e6459932911e4251f38202727ee5e8da3369

parent

19d2f9ff85fdfff0e462a4bf3e61a781dde9c92f

6 files changed, 24 insertions(+), 17 deletions(-)

jump to
M activity.goactivity.go

@@ -344,9 +344,9 @@ if ok {

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 @@ outbox, _ := jsongetstring(j, "outbox")

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 @@ handlock.Unlock()

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 @@ href, _ := jsongetstring(l, "href")

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()
M fun.gofun.go

@@ -394,8 +394,7 @@ ziggylock.Unlock()

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 @@ if err != nil {

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) }
M honk.gohonk.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 @@ stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?")

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() {
M schema.sqlschema.sql

@@ -3,7 +3,7 @@ create table honks (honkid integer primary key, userid integer, what text, honker text, xid text, rid text, dt text, url text, audience text, noise text, convoy text, whofore integer, format text, precis text, oonker text);

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);
M upgradedb.goupgradedb.go

@@ -93,6 +93,11 @@ doordie(db, "alter table files add column local integer")

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) }
M util.goutil.go

@@ -71,7 +71,7 @@

var alreadyopendb *sql.DB var dbname = "honk.db" var stmtConfig *sql.Stmt -var myVersion = 9 +var myVersion = 10 func initdb() { schema, err := ioutil.ReadFile("schema.sql")