DB query queueing
This commit is contained in:
parent
eff7d6e39b
commit
0c7c07adb4
15
db/db.go
15
db/db.go
|
@ -10,12 +10,14 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
db *sqlx.DB
|
||||
db *sqlx.DB
|
||||
queryQueue = make(chan func(), 1000)
|
||||
)
|
||||
|
||||
func Connect(params string) (err error) {
|
||||
db, err = sqlx.Connect("mysql", params)
|
||||
db.Mapper = reflectx.NewMapper("json")
|
||||
go processQueue()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -42,6 +44,17 @@ func mustSelectN(dest interface{}, query string, params interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func Queue(fun func()) {
|
||||
queryQueue <- fun
|
||||
}
|
||||
|
||||
func processQueue() {
|
||||
for {
|
||||
fun := <-queryQueue
|
||||
fun()
|
||||
}
|
||||
}
|
||||
|
||||
func measure(op string, start time.Time) {
|
||||
duration := time.Since(start).Nanoseconds()
|
||||
outcome := "succeeded"
|
||||
|
|
Loading…
Reference in New Issue