Skip to content

Commit 3010191

Browse files
krkeshavtidwall
authored andcommitted
avoid search instead of throwing error
1 parent 337348a commit 3010191

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

internal/collection/collection.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package collection
22

33
import (
4+
"math"
45
"runtime"
56

67
"github.com/tidwall/btree"
@@ -407,6 +408,13 @@ func (c *Collection) geoSearch(
407408
) bool {
408409
alive := true
409410
min, max := rtreeRect(rect)
411+
412+
// avoid search if NaN present as it results in full search
413+
if math.IsNaN(float64(min[0])) && math.IsNaN(float64(min[1])) &&
414+
math.IsNaN(float64(max[0])) && math.IsNaN(float64(max[1])) {
415+
return alive
416+
}
417+
410418
c.spatial.Search(
411419
min, max,
412420
func(_, _ [2]float32, o *object.Object) bool {

internal/server/crud.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,11 +691,11 @@ func (s *Server) cmdSET(msg *Message) (resp.Value, commandDetails, error) {
691691
}
692692
}
693693
y, err := strconv.ParseFloat(slat, 64)
694-
if err != nil || math.IsInf(y, 0) || math.IsNaN(y) {
694+
if err != nil {
695695
return retwerr(errInvalidArgument(slat))
696696
}
697697
x, err := strconv.ParseFloat(slon, 64)
698-
if err != nil || math.IsInf(x, 0) || math.IsNaN(x) {
698+
if err != nil {
699699
return retwerr(errInvalidArgument(slon))
700700
}
701701
if !hasZ {

internal/server/search.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"math"
87
"strconv"
98
"strings"
109
"time"
@@ -87,19 +86,19 @@ func parseRectArea(ltyp string, vs []string) (nvs []string,
8786
return
8887
}
8988
var minLat, minLon, maxLat, maxLon float64
90-
if minLat, err = strconv.ParseFloat(sminLat, 64); err != nil || math.IsInf(minLat, 0) || math.IsNaN(minLat) {
89+
if minLat, err = strconv.ParseFloat(sminLat, 64); err != nil {
9190
err = errInvalidArgument(sminLat)
9291
return
9392
}
94-
if minLon, err = strconv.ParseFloat(sminLon, 64); err != nil || math.IsInf(minLon, 0) || math.IsNaN(minLon) {
93+
if minLon, err = strconv.ParseFloat(sminLon, 64); err != nil {
9594
err = errInvalidArgument(sminLon)
9695
return
9796
}
98-
if maxLat, err = strconv.ParseFloat(smaxlat, 64); err != nil || math.IsInf(maxLat, 0) || math.IsNaN(maxLat) {
97+
if maxLat, err = strconv.ParseFloat(smaxlat, 64); err != nil {
9998
err = errInvalidArgument(smaxlat)
10099
return
101100
}
102-
if maxLon, err = strconv.ParseFloat(smaxlon, 64); err != nil || math.IsInf(maxLon, 0) || math.IsNaN(maxLon) {
101+
if maxLon, err = strconv.ParseFloat(smaxlon, 64); err != nil {
103102
err = errInvalidArgument(smaxlon)
104103
return
105104
}
@@ -246,11 +245,11 @@ func (s *Server) cmdSearchArgs(
246245
return
247246
}
248247
var lat, lon, meters float64
249-
if lat, err = strconv.ParseFloat(slat, 64); err != nil || math.IsInf(lat, 0) || math.IsNaN(lat) {
248+
if lat, err = strconv.ParseFloat(slat, 64); err != nil {
250249
err = errInvalidArgument(slat)
251250
return
252251
}
253-
if lon, err = strconv.ParseFloat(slon, 64); err != nil || math.IsInf(lon, 0) || math.IsNaN(lon) {
252+
if lon, err = strconv.ParseFloat(slon, 64); err != nil {
254253
err = errInvalidArgument(slon)
255254
return
256255
}
@@ -286,11 +285,11 @@ func (s *Server) cmdSearchArgs(
286285
return
287286
}
288287
var lat, lon, meters float64
289-
if lat, err = strconv.ParseFloat(slat, 64); err != nil || math.IsInf(lat, 0) || math.IsNaN(lat) {
288+
if lat, err = strconv.ParseFloat(slat, 64); err != nil {
290289
err = errInvalidArgument(slat)
291290
return
292291
}
293-
if lon, err = strconv.ParseFloat(slon, 64); err != nil || math.IsInf(lon, 0) || math.IsNaN(lon) {
292+
if lon, err = strconv.ParseFloat(slon, 64); err != nil {
294293
err = errInvalidArgument(slon)
295294
return
296295
}
@@ -345,11 +344,11 @@ func (s *Server) cmdSearchArgs(
345344
return
346345
}
347346
var lat, lon, meters, b1, b2 float64
348-
if lat, err = strconv.ParseFloat(slat, 64); err != nil || math.IsInf(lat, 0) || math.IsNaN(lat) {
347+
if lat, err = strconv.ParseFloat(slat, 64); err != nil {
349348
err = errInvalidArgument(slat)
350349
return
351350
}
352-
if lon, err = strconv.ParseFloat(slon, 64); err != nil || math.IsInf(lon, 0) || math.IsNaN(lon) {
351+
if lon, err = strconv.ParseFloat(slon, 64); err != nil {
353352
err = errInvalidArgument(slon)
354353
return
355354
}

0 commit comments

Comments
 (0)