- 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.
65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package database
|
|
|
|
import (
|
|
"orly.dev/pkg/database/indexes/types"
|
|
"orly.dev/pkg/encoders/filter"
|
|
"orly.dev/pkg/interfaces/store"
|
|
"orly.dev/pkg/utils/chk"
|
|
"orly.dev/pkg/utils/context"
|
|
)
|
|
|
|
// QueryForSerials takes a filter and returns the serials of events that match,
|
|
// sorted in reverse chronological order.
|
|
func (d *D) QueryForSerials(c context.T, f *filter.F) (
|
|
sers types.Uint40s, err error,
|
|
) {
|
|
var founds []*types.Uint40
|
|
var idPkTs []*store.IdPkTs
|
|
if f.Ids != nil && f.Ids.Len() > 0 {
|
|
for _, id := range f.Ids.ToSliceOfBytes() {
|
|
var ser *types.Uint40
|
|
if ser, err = d.GetSerialById(id); chk.E(err) {
|
|
return
|
|
}
|
|
founds = append(founds, ser)
|
|
}
|
|
var tmp []*store.IdPkTs
|
|
if tmp, err = d.GetFullIdPubkeyBySerials(founds); chk.E(err) {
|
|
return
|
|
}
|
|
idPkTs = append(idPkTs, tmp...)
|
|
|
|
// // fetch the events full id indexes so we can sort them
|
|
// for _, ser := range founds {
|
|
// // scan for the IdPkTs
|
|
// var fidpk *store.IdPkTs
|
|
// if fidpk, err = d.GetFullIdPubkeyBySerial(ser); chk.E(err) {
|
|
// return
|
|
// }
|
|
// if fidpk == nil {
|
|
// continue
|
|
// }
|
|
// idPkTs = append(idPkTs, fidpk)
|
|
// // sort by timestamp
|
|
// sort.Slice(
|
|
// idPkTs, func(i, j int) bool {
|
|
// return idPkTs[i].Ts > idPkTs[j].Ts
|
|
// },
|
|
// )
|
|
// }
|
|
} else {
|
|
if idPkTs, err = d.QueryForIds(c, f); chk.E(err) {
|
|
return
|
|
}
|
|
}
|
|
// extract the serials
|
|
for _, idpk := range idPkTs {
|
|
ser := new(types.Uint40)
|
|
if err = ser.Set(idpk.Ser); chk.E(err) {
|
|
continue
|
|
}
|
|
sers = append(sers, ser)
|
|
}
|
|
return
|
|
}
|