DB query queueing
This commit is contained in:
parent
eff7d6e39b
commit
0c7c07adb4
13
db/db.go
13
db/db.go
|
@ -11,11 +11,13 @@ import (
|
|||
|
||||
var (
|
||||
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