combine more row scanning
This commit is contained in:
parent
6a68d43997
commit
11721b9ec2
66
database.go
66
database.go
|
@ -90,35 +90,14 @@ func allusers() []login.UserInfo {
|
||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanxonk(row *sql.Row) *Honk {
|
|
||||||
h := new(Honk)
|
|
||||||
var dt, aud, onts 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.Convoy, &h.Whofore, &h.Flags, &onts)
|
|
||||||
if err != nil {
|
|
||||||
if err != sql.ErrNoRows {
|
|
||||||
log.Printf("error scanning xonk: %s", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
func getxonk(userid int64, xid string) *Honk {
|
func getxonk(userid int64, xid string) *Honk {
|
||||||
row := stmtOneXonk.QueryRow(userid, xid)
|
row := stmtOneXonk.QueryRow(userid, xid)
|
||||||
return scanxonk(row)
|
return scanhonk(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getbonk(userid int64, xid string) *Honk {
|
func getbonk(userid int64, xid string) *Honk {
|
||||||
row := stmtOneBonk.QueryRow(userid, xid)
|
row := stmtOneBonk.QueryRow(userid, xid)
|
||||||
return scanxonk(row)
|
return scanhonk(row)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getpublichonks() []*Honk {
|
func getpublichonks() []*Honk {
|
||||||
|
@ -186,27 +165,40 @@ func getsomehonks(rows *sql.Rows, err error) []*Honk {
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var honks []*Honk
|
var honks []*Honk
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var h Honk
|
h := scanhonk(rows)
|
||||||
var dt, aud, onts string
|
if h != nil {
|
||||||
err = rows.Scan(&h.ID, &h.UserID, &h.Username, &h.What, &h.Honker, &h.Oonker, &h.XID,
|
honks = append(honks, h)
|
||||||
&h.RID, &dt, &h.URL, &aud, &h.Noise, &h.Precis, &h.Convoy, &h.Whofore, &h.Flags, &onts)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("error scanning honks: %s", err)
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
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, " ")
|
|
||||||
}
|
|
||||||
honks = append(honks, &h)
|
|
||||||
}
|
}
|
||||||
rows.Close()
|
rows.Close()
|
||||||
donksforhonks(honks)
|
donksforhonks(honks)
|
||||||
return honks
|
return honks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RowLike interface {
|
||||||
|
Scan(dest ...interface{}) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func scanhonk(row RowLike) *Honk {
|
||||||
|
h := new(Honk)
|
||||||
|
var dt, aud, onts 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.Convoy, &h.Whofore, &h.Flags, &onts)
|
||||||
|
if err != nil {
|
||||||
|
if err != sql.ErrNoRows {
|
||||||
|
log.Printf("error scanning honk: %s", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
func donksforhonks(honks []*Honk) {
|
func donksforhonks(honks []*Honk) {
|
||||||
db := opendatabase()
|
db := opendatabase()
|
||||||
var ids []string
|
var ids []string
|
||||||
|
|
Loading…
Reference in New Issue