all repos — honk @ 2f5e3e464ccf1dee38e702d9a1ad83a929d1e488

my fork of honk

don't store exploded onts in honks
Ted Unangst tedu@tedunangst.com
Sun, 22 Sep 2019 17:00:14 -0400
commit

2f5e3e464ccf1dee38e702d9a1ad83a929d1e488

parent

750d79ff5a22cc132d6694f0e09393cd2450e52f

4 files changed, 34 insertions(+), 20 deletions(-)

jump to
M database.godatabase.go

@@ -181,9 +181,9 @@ }

func scanhonk(row RowLike) *Honk { h := new(Honk) - var dt, aud, onts string + var dt, aud string err := row.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, &h.XID, &h.RID, - &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Format, &h.Convoy, &h.Whofore, &h.Flags, &onts) + &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Format, &h.Convoy, &h.Whofore, &h.Flags) if err != nil { if err != sql.ErrNoRows { log.Printf("error scanning honk: %s", err)

@@ -193,9 +193,6 @@ }

h.Date, _ = time.Parse(dbtimeformat, dt) h.Audience = strings.Split(aud, " ") h.Public = !keepitquiet(h.Audience) - if len(onts) > 0 { - h.Onts = strings.Split(onts, " ") - } return h }

@@ -207,6 +204,7 @@ for _, h := range honks {

ids = append(ids, fmt.Sprintf("%d", h.ID)) hmap[h.ID] = h } + // grab donks q := fmt.Sprintf("select honkid, donks.fileid, xid, name, description, url, media, local from donks join files on donks.fileid = files.fileid where honkid in (%s)", strings.Join(ids, ",")) rows, err := db.Query(q) if err != nil {

@@ -225,6 +223,28 @@ }

h := hmap[hid] h.Donks = append(h.Donks, &d) } + rows.Close() + + // grab onts + q = fmt.Sprintf("select honkid, ontology from onts where honkid in (%s)", strings.Join(ids, ",")) + rows, err = db.Query(q) + if err != nil { + log.Printf("error querying onts: %s", err) + return + } + defer rows.Close() + for rows.Next() { + var hid int64 + var o string + err = rows.Scan(&hid, &o) + if err != nil { + log.Printf("error scanning donk: %s", err) + continue + } + h := hmap[hid] + h.Onts = append(h.Onts, o) + } + rows.Close() } func savehonk(h *Honk) error {

@@ -233,7 +253,7 @@ aud := strings.Join(h.Audience, " ")

res, err := stmtSaveHonk.Exec(h.UserID, h.What, h.Honker, h.XID, h.RID, dt, h.URL, aud, h.Noise, h.Convoy, h.Whofore, h.Format, h.Precis, - h.Oonker, h.Flags, strings.Join(h.Onts, " ")) + h.Oonker, h.Flags) if err != nil { log.Printf("err saving honk: %s", err) return err

@@ -341,7 +361,7 @@ stmtUpdateCombos = preparetodie(db, "update honkers set combos = ? where honkerid = ? and userid = ?")

stmtOneHonker = preparetodie(db, "select xid from honkers where name = ? and userid = ?") stmtDubbers = preparetodie(db, "select honkerid, userid, name, xid, flavor from honkers where userid = ? and flavor = 'dub'") - selecthonks := "select honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, format, convoy, whofore, flags, onts from honks join users on honks.userid = users.userid " + selecthonks := "select honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, format, convoy, whofore, flags from honks join users on honks.userid = users.userid " limit := " order by honks.honkid desc limit 250" butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)" stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?")

@@ -358,7 +378,7 @@ stmtHonksByConvoy = preparetodie(db, selecthonks+"where (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit)

stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit) stmtSaveOld = preparetodie(db, "insert into forsaken (honkid, precis, noise) values (?, ?, ?)") - stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags, onts) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") + stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, dt = ? where honkid = ?") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)")
M schema.sqlschema.sql

@@ -1,5 +1,5 @@

-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, flags integer, onts text); +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, flags integer); create table donks (honkid integer, fileid integer); create table files(fileid integer primary key, xid text, name text, description 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);

@@ -19,6 +19,7 @@ create index idx_zonkersname on zonkers(name);

create index idx_filesxid on files(xid); create index idx_filesurl on files(url); create index idx_ontology on onts(ontology); +create index idx_onthonkid on onts(honkid); create table config (key text, value text);
M upgradedb.goupgradedb.go

@@ -122,13 +122,11 @@ doordie(db, "update honks set flags = 0")

doordie(db, "update config set value = 14 where key = 'dbversion'") fallthrough case 14: - doordie(db, "alter table honks add column onts text") doordie(db, "create table onts (ontology text, honkid integer)") doordie(db, "create index idx_ontology on onts(ontology)") doordie(db, "update config set value = 15 where key = 'dbversion'") fallthrough case 15: - doordie(db, "update honks set onts = ''") doordie(db, "delete from onts") ontmap := make(map[int64][]string) rows, err := db.Query("select honkid, noise from honks")

@@ -157,19 +155,11 @@ tx, err := db.Begin()

if err != nil { log.Fatalf("can't begin: %s", err) } - stmtHonk, err := tx.Prepare("update honks set onts = ? where honkid = ?") - if err != nil { - log.Fatal(err) - } stmtOnts, err := tx.Prepare("insert into onts (ontology, honkid) values (?, ?)") if err != nil { log.Fatal(err) } for honkid, onts := range ontmap { - _, err = stmtHonk.Exec(strings.Join(onts, " "), honkid) - if err != nil { - log.Fatal(err) - } for _, o := range onts { _, err = stmtOnts.Exec(strings.ToLower(o), honkid) if err != nil {

@@ -193,6 +183,9 @@ doordie(db, "create table forsaken (honkid integer, precis text, noise text)")

doordie(db, "update config set value = 18 where key = 'dbversion'") fallthrough case 18: + doordie(db, "create index idx_onthonkid on onts(honkid)") + doordie(db, "update config set value = 19 where key = 'dbversion'") + case 19: default: log.Fatalf("can't upgrade unknown version %d", dbversion) }
M util.goutil.go

@@ -72,7 +72,7 @@

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