diff --git a/go.mod b/go.mod index b6e17547..34bc5063 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/prometheus/client_golang v1.12.1 github.com/streadway/amqp v1.0.0 github.com/tidwall/assert v0.1.0 - github.com/tidwall/btree v1.4.3 + github.com/tidwall/btree v1.4.4 github.com/tidwall/buntdb v1.2.9 github.com/tidwall/geojson v1.3.6 github.com/tidwall/gjson v1.14.3 diff --git a/go.sum b/go.sum index 9905964d..8674dd65 100644 --- a/go.sum +++ b/go.sum @@ -350,8 +350,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/tidwall/assert v0.1.0 h1:aWcKyRBUAdLoVebxo95N7+YZVTFF/ASTr7BN4sLP6XI= github.com/tidwall/assert v0.1.0/go.mod h1:QLYtGyeqse53vuELQheYl9dngGCJQ+mTtlxcktb+Kj8= github.com/tidwall/btree v1.1.0/go.mod h1:TzIRzen6yHbibdSfK6t8QimqbUnoxUSrZfeW7Uob0q4= -github.com/tidwall/btree v1.4.3 h1:Lf5U/66bk0ftNppOBjVoy/AIPBrLMkheBp4NnSNiYOo= -github.com/tidwall/btree v1.4.3/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE= +github.com/tidwall/btree v1.4.4 h1:tOsRz2Upq6BEJz8T++C6THzNh9xGWymBOOSfA7ffNXY= +github.com/tidwall/btree v1.4.4/go.mod h1:LGm8L/DZjPLmeWGjv5kFrY8dL4uVhMmzmmLYmsObdKE= github.com/tidwall/buntdb v1.2.9 h1:XVz684P7X6HCTrdr385yDZWB1zt/n20ZNG3M1iGyFm4= github.com/tidwall/buntdb v1.2.9/go.mod h1:IwyGSvvDg6hnKSIhtdZ0AqhCZGH8ukdtCAzaP8fI1X4= github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE= diff --git a/internal/object/object_binary.go b/internal/object/object_binary.go index f84ccb45..832c2b50 100644 --- a/internal/object/object_binary.go +++ b/internal/object/object_binary.go @@ -63,24 +63,18 @@ func varint(s string) (int64, int) { } func (o *Object) ID() string { - if o == nil { - return "" + if o.head[1] == 0 { + return o.head[2:] } _, n := varint(o.head[1:]) return o.head[1+n:] } func (o *Object) Fields() field.List { - if o == nil { - return field.List{} - } return o.fields } func (o *Object) Expires() int64 { - if o == nil { - return 0 - } ex, _ := varint(o.head[1:]) return ex } @@ -111,15 +105,15 @@ func (o *Object) IsSpatial() bool { } func (o *Object) Weight() int { - if o == nil { - return 0 - } var weight int weight += len(o.ID()) - if o.IsSpatial() { - weight += o.Geo().NumPoints() * 16 - } else { - weight += len(o.Geo().String()) + ogeo := o.geo() + if ogeo != nil { + if o.IsSpatial() { + weight += ogeo.NumPoints() * 16 + } else { + weight += len(ogeo.String()) + } } weight += o.Fields().Weight() return weight @@ -127,7 +121,10 @@ func (o *Object) Weight() int { func makeHead(kind byte, id string, expires int64) string { var exb [20]byte - exn := binary.PutVarint(exb[:], expires) + exn := 1 + if expires != 0 { + exn = binary.PutVarint(exb[:], expires) + } n := 1 + exn + len(id) head := make([]byte, n) head[0] = kind