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:
65
pkg/database/query-for-serials.go
Normal file
65
pkg/database/query-for-serials.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"database.orly/indexes/types"
|
||||
"encoders.orly/filter"
|
||||
"interfaces.orly/store"
|
||||
"lol.mleku.dev/chk"
|
||||
)
|
||||
|
||||
// QueryForSerials takes a filter and returns the serials of events that match,
|
||||
// sorted in reverse chronological order.
|
||||
func (d *D) QueryForSerials(c context.Context, 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
|
||||
}
|
||||
Reference in New Issue
Block a user