close some queries when done

This commit is contained in:
Ted Unangst 2019-06-16 21:21:56 -04:00
parent ce0f473e81
commit 2ac28709ea
2 changed files with 6 additions and 3 deletions

1
fun.go
View File

@ -476,6 +476,7 @@ func bitethethumbs() {
return return
} }
defer rows.Close() defer rows.Close()
thumblock.Lock() thumblock.Lock()
defer thumblock.Unlock() defer thumblock.Unlock()
thumbbiters = make(map[int64]map[string]bool) thumbbiters = make(map[int64]map[string]bool)

View File

@ -391,6 +391,7 @@ func xzone(w http.ResponseWriter, r *http.Request) {
log.Printf("query err: %s", err) log.Printf("query err: %s", err)
return return
} }
defer rows.Close()
for rows.Next() { for rows.Next() {
var s string var s string
rows.Scan(&s) rows.Scan(&s)
@ -1123,13 +1124,13 @@ type Zonker struct {
} }
func zonkzone(w http.ResponseWriter, r *http.Request) { func zonkzone(w http.ResponseWriter, r *http.Request) {
db := opendatabase()
userinfo := login.GetUserInfo(r) userinfo := login.GetUserInfo(r)
rows, err := db.Query("select zonkerid, name, wherefore from zonkers where userid = ?", userinfo.UserID) rows, err := stmtGetZonkers.Query(userinfo.UserID)
if err != nil { if err != nil {
log.Printf("err: %s", err) log.Printf("err: %s", err)
return return
} }
defer rows.Close()
var zonkers []Zonker var zonkers []Zonker
for rows.Next() { for rows.Next() {
var z Zonker var z Zonker
@ -1428,7 +1429,7 @@ var stmtHonksByHonker, stmtSaveHonk, stmtFileData, stmtWhatAbout *sql.Stmt
var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt var stmtFindXonk, stmtSaveDonk, stmtFindFile, stmtSaveFile *sql.Stmt
var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt var stmtAddDoover, stmtGetDoovers, stmtLoadDoover, stmtZapDoover *sql.Stmt
var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt var stmtHasHonker, stmtThumbBiters, stmtZonkIt, stmtZonkDonks, stmtSaveZonker *sql.Stmt
var stmtRecentHonkers, stmtGetXonker, stmtSaveXonker *sql.Stmt var stmtGetZonkers, stmtRecentHonkers, stmtGetXonker, stmtSaveXonker *sql.Stmt
func preparetodie(db *sql.DB, s string) *sql.Stmt { func preparetodie(db *sql.DB, s string) *sql.Stmt {
stmt, err := db.Prepare(s) stmt, err := db.Prepare(s)
@ -1474,6 +1475,7 @@ func prepareStatements(db *sql.DB) {
stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?") stmtLoadDoover = preparetodie(db, "select tries, username, rcpt, msg from doovers where dooverid = ?")
stmtZapDoover = preparetodie(db, "delete 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')") stmtThumbBiters = preparetodie(db, "select userid, name, wherefore from zonkers where (wherefore = 'zonker' or wherefore = 'zurl' or wherefore = 'zword')")
stmtGetZonkers = preparetodie(db, "select zonkerid, name, wherefore from zonkers where userid = ?")
stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)") stmtSaveZonker = preparetodie(db, "insert into zonkers (userid, name, wherefore) values (?, ?, ?)")
stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?") stmtGetXonker = preparetodie(db, "select info from xonkers where name = ? and flavor = ?")
stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)") stmtSaveXonker = preparetodie(db, "insert into xonkers (name, info, flavor) values (?, ?, ?)")