Migrate package imports from next.orly.dev to new orly domain structure; add new varint and binary encoders with comprehensive tests; enhance existing tag and envelope implementations with additional methods, validations, and test coverage; introduce shared test.sh script for streamlined testing across modules.
This commit is contained in:
51
pkg/database/get-serials-by-range.go
Normal file
51
pkg/database/get-serials-by-range.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sort"
|
||||
|
||||
"database.orly/indexes/types"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
"lol.mleku.dev/chk"
|
||||
)
|
||||
|
||||
func (d *D) GetSerialsByRange(idx Range) (
|
||||
sers types.Uint40s, err error,
|
||||
) {
|
||||
if err = d.View(
|
||||
func(txn *badger.Txn) (err error) {
|
||||
it := txn.NewIterator(
|
||||
badger.IteratorOptions{
|
||||
Reverse: true,
|
||||
},
|
||||
)
|
||||
defer it.Close()
|
||||
for it.Seek(idx.End); it.Valid(); it.Next() {
|
||||
item := it.Item()
|
||||
var key []byte
|
||||
key = item.Key()
|
||||
if bytes.Compare(
|
||||
key[:len(key)-5], idx.Start,
|
||||
) < 0 {
|
||||
// didn't find it within the timestamp range
|
||||
return
|
||||
}
|
||||
ser := new(types.Uint40)
|
||||
buf := bytes.NewBuffer(key[len(key)-5:])
|
||||
if err = ser.UnmarshalRead(buf); chk.E(err) {
|
||||
return
|
||||
}
|
||||
sers = append(sers, ser)
|
||||
}
|
||||
return
|
||||
},
|
||||
); chk.E(err) {
|
||||
return
|
||||
}
|
||||
sort.Slice(
|
||||
sers, func(i, j int) bool {
|
||||
return sers[i].Get() < sers[j].Get()
|
||||
},
|
||||
)
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user