save donks for chonks
This commit is contained in:
parent
d2e6507a0b
commit
a48f58fbec
|
@ -902,6 +902,7 @@ func xonksaver(user *WhatAbout, item junk.Junk, origin string) *Honk {
|
|||
Date: xonk.Date,
|
||||
Noise: xonk.Noise,
|
||||
Format: xonk.Format,
|
||||
Donks: xonk.Donks,
|
||||
}
|
||||
savechonk(&ch)
|
||||
return nil
|
||||
|
|
25
database.go
25
database.go
|
@ -484,9 +484,26 @@ func finddonk(url string) *Donk {
|
|||
|
||||
func savechonk(ch *Chonk) error {
|
||||
dt := ch.Date.UTC().Format(dbtimeformat)
|
||||
res, err := stmtSaveChonk.Exec(ch.UserID, ch.XID, ch.Who, ch.Target, dt, ch.Noise, ch.Format)
|
||||
db := opendatabase()
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
log.Printf("can't begin tx: %s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
res, err := tx.Stmt(stmtSaveChonk).Exec(ch.UserID, ch.XID, ch.Who, ch.Target, dt, ch.Noise, ch.Format)
|
||||
if err == nil {
|
||||
ch.ID, _ = res.LastInsertId()
|
||||
for _, d := range ch.Donks {
|
||||
_, err := tx.Stmt(stmtSaveDonk).Exec(-1, ch.ID, d.FileID)
|
||||
if err != nil {
|
||||
log.Printf("error saving donk: %s", err)
|
||||
break
|
||||
}
|
||||
}
|
||||
err = tx.Commit()
|
||||
} else {
|
||||
tx.Rollback()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
@ -608,7 +625,7 @@ func deletehonk(honkid int64) error {
|
|||
|
||||
func saveextras(tx *sql.Tx, h *Honk) error {
|
||||
for _, d := range h.Donks {
|
||||
_, err := tx.Stmt(stmtSaveDonk).Exec(h.ID, d.FileID)
|
||||
_, err := tx.Stmt(stmtSaveDonk).Exec(h.ID, -1, d.FileID)
|
||||
if err != nil {
|
||||
log.Printf("error saving donk: %s", err)
|
||||
return err
|
||||
|
@ -706,7 +723,7 @@ func cleanupdb(arg string) {
|
|||
sqlargs = append(sqlargs, expdate)
|
||||
}
|
||||
doordie(db, "delete from honks where flags & 4 = 0 and whofore = 0 and "+where, sqlargs...)
|
||||
doordie(db, "delete from donks where honkid not in (select honkid from honks)")
|
||||
doordie(db, "delete from donks where honkid > 0 and honkid not in (select honkid from honks)")
|
||||
doordie(db, "delete from onts where honkid not in (select honkid from honks)")
|
||||
doordie(db, "delete from honkmeta where honkid not in (select honkid from honks)")
|
||||
|
||||
|
@ -818,7 +835,7 @@ func prepareStatements(db *sql.DB) {
|
|||
stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, whofore = ?, dt = ? where honkid = ?")
|
||||
stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)")
|
||||
stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?")
|
||||
stmtSaveDonk = preparetodie(db, "insert into donks (honkid, fileid) values (?, ?)")
|
||||
stmtSaveDonk = preparetodie(db, "insert into donks (honkid, chonkid, fileid) values (?, ?, ?)")
|
||||
stmtDeleteDonks = preparetodie(db, "delete from donks where honkid = ?")
|
||||
stmtSaveFile = preparetodie(db, "insert into filemeta (xid, name, description, url, media, local) values (?, ?, ?, ?, ?, ?)")
|
||||
blobdb := openblobdb()
|
||||
|
|
1
honk.go
1
honk.go
|
@ -103,6 +103,7 @@ type Chonk struct {
|
|||
Date time.Time
|
||||
Noise string
|
||||
Format string
|
||||
Donks []*Donk
|
||||
Handle string
|
||||
HTML template.HTML
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ var sqlSchema = `
|
|||
|
||||
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 chonks (chonkid integer primary key, userid integer, xid text, who txt, target text, dt text, noise text, format text);
|
||||
create table donks (honkid integer, fileid integer);
|
||||
create table donks (honkid integer, chonkid 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, meta text);
|
||||
create table xonkers (xonkerid integer primary key, name text, info text, flavor text, dt text);
|
||||
|
@ -19,6 +19,8 @@ create index idx_honksxid on honks(xid);
|
|||
create index idx_honksconvoy on honks(convoy);
|
||||
create index idx_honkshonker on honks(honker);
|
||||
create index idx_honksoonker on honks(oonker);
|
||||
create index idx_donkshonk on donks(honkid);
|
||||
create index idx_donkschonk on donks(chonkid);
|
||||
create index idx_honkerxid on honkers(xid);
|
||||
create index idx_xonkername on xonkers(name);
|
||||
create index idx_zonkersname on zonkers(name);
|
||||
|
|
|
@ -1,7 +1,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, flags integer);
|
||||
create table chonks (chonkid integer primary key, userid integer, xid text, who txt, target text, dt text, noise text, format text);
|
||||
create table donks (honkid integer, fileid integer);
|
||||
create table donks (honkid integer, chonkid 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, meta text);
|
||||
create table xonkers (xonkerid integer primary key, name text, info text, flavor text, dt text);
|
||||
|
@ -16,6 +16,8 @@ create index idx_honksxid on honks(xid);
|
|||
create index idx_honksconvoy on honks(convoy);
|
||||
create index idx_honkshonker on honks(honker);
|
||||
create index idx_honksoonker on honks(oonker);
|
||||
create index idx_donkshonk on donks(honkid);
|
||||
create index idx_donkschonk on donks(chonkid);
|
||||
create index idx_honkerxid on honkers(xid);
|
||||
create index idx_xonkername on xonkers(name);
|
||||
create index idx_zonkersname on zonkers(name);
|
||||
|
|
|
@ -24,7 +24,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var myVersion = 35
|
||||
var myVersion = 36
|
||||
|
||||
func doordie(db *sql.DB, s string, args ...interface{}) {
|
||||
_, err := db.Exec(s, args...)
|
||||
|
@ -370,6 +370,13 @@ func upgradedb() {
|
|||
doordie(db, "update config set value = 35 where key = 'dbversion'")
|
||||
fallthrough
|
||||
case 35:
|
||||
doordie(db, "alter table donks add column chonkid integer")
|
||||
doordie(db, "update donks set chonkid = -1")
|
||||
doordie(db, "create index idx_donkshonk on donks(honkid)")
|
||||
doordie(db, "create index idx_donkschonk on donks(chonkid)")
|
||||
doordie(db, "update config set value = 36 where key = 'dbversion'")
|
||||
fallthrough
|
||||
case 36:
|
||||
|
||||
default:
|
||||
log.Fatalf("can't upgrade unknown version %d", dbversion)
|
||||
|
|
Loading…
Reference in New Issue