From 3167be73bbbabfaf2269930d27cb1454ff45782b Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Tue, 28 Feb 2017 00:00:39 +0000 Subject: [PATCH] No need to pass statements in from goroutine A series of statements on one request are always handled and run serially, so there is no need to loop over them in a goroutine. --- db/db.go | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/db/db.go b/db/db.go index 2e17c1a5..6d90c09e 100644 --- a/db/db.go +++ b/db/db.go @@ -217,39 +217,18 @@ func (e *executor) execute(quit <-chan bool, send chan<- *Response) { } }() - stms := make(chan sql.Statement) - // Loop over the defined query statements and - // pass them to the statement processing - // channel for execution. + // process them, while listening for the quit + // channel to see if the client has gone away. - go func() { - for _, stm := range e.ast.Statements { - stms <- stm - } - close(stms) - }() - - // Listen for any new statements to process and - // at the same time listen for the quit signal - // notifying us whether the client has gone away. - - for { + for _, stm := range e.ast.Statements { select { case <-quit: return - case stm, open := <-stms: - - // If we have reached the end of the statement - // processing channel then return out of this - // for loop and exit. - - if !open { - return - } + default: // If we are not inside a global transaction // then reset the error to nil so that the