- pkg/encoders/event/codectester/divider/main.go - Added missing import for `orly.dev/pkg/utils`. - pkg/crypto/encryption/nip44.go - Imported `orly.dev/pkg/utils`. - pkg/crypto/ec/musig2/sign.go - Introduced `orly.dev/pkg/utils` import. - pkg/crypto/keys/keys.go - Included `orly.dev/pkg/utils`. - pkg/database/query-for-serials.go - Updated `QueryForSerials` to use `GetFullIdPubkeyBySerials` for batch retrieval. - Removed unnecessary `sort` package import. - Replaced outdated logic for serial resolution. - pkg/database/get-fullidpubkey-by-serials.go - Added new implementation for `GetFullIdPubkeyBySerials` for efficient batch serial lookups. - pkg/database/get-serial-by-id.go - Added placeholder for alternative serial lookup method. - pkg/database/database.go - Enabled `opts.Compression = options.None` in database configuration. - pkg/database/save-event.go - Replaced loop-based full ID lookup with `GetFullIdPubkeyBySerials` for efficiency. - pkg/database/get-serials-by-range.go - Added missing `sort.Slice` to enforce ascending order for serials. - pkg/crypto/ec/taproot/taproot.go - Imported `orly.dev/pkg/utils`. - pkg/crypto/ec/musig2/keys.go - Added `orly.dev/pkg/utils` import. - pkg/database/get-fullidpubkey-by-serial.go - Removed legacy `GetFullIdPubkeyBySerials` implementation. - pkg/database/query-for-ids.go - Refactored `QueryForIds` to use batched lookups via `GetFullIdPubkeyBySerials`. - Consolidated batch result deduplication logic. - Simplified code by removing redundant steps and checks.
51 lines
955 B
Go
51 lines
955 B
Go
package database
|
|
|
|
import (
|
|
"bytes"
|
|
"github.com/dgraph-io/badger/v4"
|
|
"orly.dev/pkg/database/indexes/types"
|
|
"orly.dev/pkg/utils/chk"
|
|
"sort"
|
|
)
|
|
|
|
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
|
|
}
|