mirror of https://github.com/tidwall/tile38.git
avoid recover calls for non-lua queries
The defer recover() pattern is expensive and only Lua queries require it, so for now we'll just check if lua is being used before calling.
This commit is contained in:
parent
3568edf44c
commit
7538cc73ff
|
@ -27,6 +27,7 @@ func (c *Controller) cmdScan(msg *server.Message) (res resp.Value, err error) {
|
|||
vs := msg.Values[1:]
|
||||
|
||||
s, err := c.cmdScanArgs(vs)
|
||||
if s.usingLua() {
|
||||
defer s.Close()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -35,6 +36,7 @@ func (c *Controller) cmdScan(msg *server.Message) (res resp.Value, err error) {
|
|||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
if err != nil {
|
||||
return server.NOMessage, err
|
||||
}
|
||||
|
|
|
@ -42,11 +42,15 @@ func (s liveFenceSwitches) Error() string {
|
|||
}
|
||||
|
||||
func (s liveFenceSwitches) Close() {
|
||||
for _, whereeval := range s.searchScanBaseTokens.whereevals {
|
||||
for _, whereeval := range s.whereevals {
|
||||
whereeval.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s liveFenceSwitches) usingLua() bool {
|
||||
return len(s.whereevals) > 0
|
||||
}
|
||||
|
||||
func (c *Controller) cmdSearchArgs(cmd string, vs []resp.Value, types []string) (s liveFenceSwitches, err error) {
|
||||
if vs, s.searchScanBaseTokens, err = c.parseSearchScanBaseTokens(cmd, vs); err != nil {
|
||||
return
|
||||
|
@ -295,6 +299,7 @@ func (c *Controller) cmdNearby(msg *server.Message) (res resp.Value, err error)
|
|||
vs := msg.Values[1:]
|
||||
wr := &bytes.Buffer{}
|
||||
s, err := c.cmdSearchArgs("nearby", vs, nearbyTypes)
|
||||
if s.usingLua() {
|
||||
defer s.Close()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -303,6 +308,7 @@ func (c *Controller) cmdNearby(msg *server.Message) (res resp.Value, err error)
|
|||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
if err != nil {
|
||||
return server.NOMessage, err
|
||||
}
|
||||
|
@ -402,6 +408,7 @@ func (c *Controller) cmdWithinOrIntersects(cmd string, msg *server.Message) (res
|
|||
|
||||
wr := &bytes.Buffer{}
|
||||
s, err := c.cmdSearchArgs(cmd, vs, withinOrIntersectsTypes)
|
||||
if s.usingLua() {
|
||||
defer s.Close()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -410,7 +417,7 @@ func (c *Controller) cmdWithinOrIntersects(cmd string, msg *server.Message) (res
|
|||
return
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
if err != nil {
|
||||
return server.NOMessage, err
|
||||
}
|
||||
|
@ -485,6 +492,7 @@ func (c *Controller) cmdSearch(msg *server.Message) (res resp.Value, err error)
|
|||
|
||||
wr := &bytes.Buffer{}
|
||||
s, err := c.cmdSeachValuesArgs(vs)
|
||||
if s.usingLua() {
|
||||
defer s.Close()
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
|
@ -493,6 +501,7 @@ func (c *Controller) cmdSearch(msg *server.Message) (res resp.Value, err error)
|
|||
return
|
||||
}
|
||||
}()
|
||||
}
|
||||
if err != nil {
|
||||
return server.NOMessage, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue