DB query queueing
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user