only join strings once

This commit is contained in:
Ted Unangst 2019-10-30 03:36:28 -04:00
parent c0c51e84d0
commit e38684f4d2
1 changed files with 5 additions and 3 deletions

View File

@ -372,8 +372,9 @@ func donksforhonks(honks []*Honk) {
ids = append(ids, fmt.Sprintf("%d", h.ID)) ids = append(ids, fmt.Sprintf("%d", h.ID))
hmap[h.ID] = h hmap[h.ID] = h
} }
idset := strings.Join(ids, ",")
// grab donks // grab donks
q := fmt.Sprintf("select honkid, donks.fileid, xid, name, description, url, media, local from donks join filemeta on donks.fileid = filemeta.fileid where honkid in (%s)", strings.Join(ids, ",")) q := fmt.Sprintf("select honkid, donks.fileid, xid, name, description, url, media, local from donks join filemeta on donks.fileid = filemeta.fileid where honkid in (%s)", idset)
rows, err := db.Query(q) rows, err := db.Query(q)
if err != nil { if err != nil {
log.Printf("error querying donks: %s", err) log.Printf("error querying donks: %s", err)
@ -394,7 +395,7 @@ func donksforhonks(honks []*Honk) {
rows.Close() rows.Close()
// grab onts // grab onts
q = fmt.Sprintf("select honkid, ontology from onts where honkid in (%s)", strings.Join(ids, ",")) q = fmt.Sprintf("select honkid, ontology from onts where honkid in (%s)", idset)
rows, err = db.Query(q) rows, err = db.Query(q)
if err != nil { if err != nil {
log.Printf("error querying onts: %s", err) log.Printf("error querying onts: %s", err)
@ -413,8 +414,9 @@ func donksforhonks(honks []*Honk) {
h.Onts = append(h.Onts, o) h.Onts = append(h.Onts, o)
} }
rows.Close() rows.Close()
// grab meta // grab meta
q = fmt.Sprintf("select honkid, genus, json from honkmeta where honkid in (%s)", strings.Join(ids, ",")) q = fmt.Sprintf("select honkid, genus, json from honkmeta where honkid in (%s)", idset)
rows, err = db.Query(q) rows, err = db.Query(q)
if err != nil { if err != nil {
log.Printf("error querying honkmeta: %s", err) log.Printf("error querying honkmeta: %s", err)