since and until are not pointers anymore because that is too annoying.
This commit is contained in:
@@ -27,8 +27,8 @@ func prepareQueries(filter nostr.Filter) (
|
||||
}
|
||||
|
||||
var until uint32 = 4294967295
|
||||
if filter.Until != nil {
|
||||
if fu := uint32(*filter.Until); fu < until {
|
||||
if filter.Until != 0 {
|
||||
if fu := uint32(filter.Until); fu < until {
|
||||
until = fu + 1
|
||||
}
|
||||
}
|
||||
@@ -38,8 +38,8 @@ func prepareQueries(filter nostr.Filter) (
|
||||
}
|
||||
|
||||
// this is where we'll end the iteration
|
||||
if filter.Since != nil {
|
||||
if fs := uint32(*filter.Since); fs > since {
|
||||
if filter.Since != 0 {
|
||||
if fs := uint32(filter.Since); fs > since {
|
||||
since = fs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,14 +54,14 @@ func (b *BlugeBackend) QueryEvents(filter nostr.Filter) iter.Seq[nostr.Event] {
|
||||
q = complicatedQuery
|
||||
}
|
||||
|
||||
if filter.Since != nil || filter.Until != nil {
|
||||
if filter.Since != 0 || filter.Until != 0 {
|
||||
min := 0.0
|
||||
if filter.Since != nil {
|
||||
min = float64(*filter.Since)
|
||||
if filter.Since != 0 {
|
||||
min = float64(filter.Since)
|
||||
}
|
||||
max := float64(nostr.Now())
|
||||
if filter.Until != nil {
|
||||
max = float64(*filter.Until)
|
||||
if filter.Until != 0 {
|
||||
max = float64(filter.Until)
|
||||
}
|
||||
dateRangeQ := bluge.NewNumericRangeInclusiveQuery(min, max, true, true)
|
||||
dateRangeQ.SetField(createdAtField)
|
||||
|
||||
@@ -36,8 +36,8 @@ func (b *LMDBBackend) prepareQueries(filter nostr.Filter) (
|
||||
}
|
||||
|
||||
var until uint32 = 4294967295
|
||||
if filter.Until != nil {
|
||||
if fu := uint32(*filter.Until); fu < until {
|
||||
if filter.Until != 0 {
|
||||
if fu := uint32(filter.Until); fu < until {
|
||||
until = fu + 1
|
||||
}
|
||||
}
|
||||
@@ -62,8 +62,8 @@ func (b *LMDBBackend) prepareQueries(filter nostr.Filter) (
|
||||
}
|
||||
|
||||
// this is where we'll end the iteration
|
||||
if filter.Since != nil {
|
||||
if fs := uint32(*filter.Since); fs > since {
|
||||
if filter.Since != 0 {
|
||||
if fs := uint32(filter.Since); fs > since {
|
||||
since = fs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ func (il *IndexingLayer) prepareQueries(filter nostr.Filter) (
|
||||
}
|
||||
|
||||
var until uint32 = 4294967295
|
||||
if filter.Until != nil {
|
||||
if fu := uint32(*filter.Until); fu < until {
|
||||
if filter.Until != 0 {
|
||||
if fu := uint32(filter.Until); fu < until {
|
||||
until = fu + 1
|
||||
}
|
||||
}
|
||||
@@ -51,8 +51,8 @@ func (il *IndexingLayer) prepareQueries(filter nostr.Filter) (
|
||||
}()
|
||||
|
||||
// this is where we'll end the iteration
|
||||
if filter.Since != nil {
|
||||
if fs := uint32(*filter.Since); fs > since {
|
||||
if filter.Since != 0 {
|
||||
if fs := uint32(filter.Since); fs > since {
|
||||
since = fs
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ func (b *SliceStore) QueryEvents(filter nostr.Filter) iter.Seq[nostr.Event] {
|
||||
// efficiently determine where to start and end
|
||||
start := 0
|
||||
end := len(b.internal)
|
||||
if filter.Until != nil {
|
||||
start, _ = slices.BinarySearchFunc(b.internal, *filter.Until, eventTimestampComparator)
|
||||
if filter.Until != 0 {
|
||||
start, _ = slices.BinarySearchFunc(b.internal, filter.Until, eventTimestampComparator)
|
||||
}
|
||||
if filter.Since != nil {
|
||||
end, _ = slices.BinarySearchFunc(b.internal, *filter.Since, eventTimestampComparator)
|
||||
if filter.Since != 0 {
|
||||
end, _ = slices.BinarySearchFunc(b.internal, filter.Since, eventTimestampComparator)
|
||||
}
|
||||
|
||||
// ham
|
||||
|
||||
24
filter.go
24
filter.go
@@ -11,8 +11,8 @@ type Filter struct {
|
||||
Kinds []Kind
|
||||
Authors []PubKey
|
||||
Tags TagMap
|
||||
Since *Timestamp
|
||||
Until *Timestamp
|
||||
Since Timestamp
|
||||
Until Timestamp
|
||||
Limit int
|
||||
Search string
|
||||
|
||||
@@ -32,11 +32,11 @@ func (ef Filter) Matches(event Event) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if ef.Since != nil && event.CreatedAt < *ef.Since {
|
||||
if ef.Since != 0 && event.CreatedAt < ef.Since {
|
||||
return false
|
||||
}
|
||||
|
||||
if ef.Until != nil && event.CreatedAt > *ef.Until {
|
||||
if ef.Until != 0 && event.CreatedAt > ef.Until {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -92,11 +92,11 @@ func FilterEqual(a Filter, b Filter) bool {
|
||||
}
|
||||
}
|
||||
|
||||
if !arePointerValuesEqual(a.Since, b.Since) {
|
||||
if a.Since != b.Since {
|
||||
return false
|
||||
}
|
||||
|
||||
if !arePointerValuesEqual(a.Until, b.Until) {
|
||||
if a.Until != b.Until {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -117,6 +117,8 @@ func (ef Filter) Clone() Filter {
|
||||
Limit: ef.Limit,
|
||||
Search: ef.Search,
|
||||
LimitZero: ef.LimitZero,
|
||||
Since: ef.Since,
|
||||
Until: ef.Until,
|
||||
}
|
||||
|
||||
if ef.IDs != nil {
|
||||
@@ -140,16 +142,6 @@ func (ef Filter) Clone() Filter {
|
||||
}
|
||||
}
|
||||
|
||||
if ef.Since != nil {
|
||||
since := *ef.Since
|
||||
clone.Since = &since
|
||||
}
|
||||
|
||||
if ef.Until != nil {
|
||||
until := *ef.Until
|
||||
clone.Until = &until
|
||||
}
|
||||
|
||||
return clone
|
||||
}
|
||||
|
||||
|
||||
@@ -97,22 +97,16 @@ func easyjson4d398eaaDecodeGithubComNbdWtfGoNostr(in *jlexer.Lexer, out *Filter)
|
||||
case "since":
|
||||
if in.IsNull() {
|
||||
in.Skip()
|
||||
out.Since = nil
|
||||
out.Since = 0
|
||||
} else {
|
||||
if out.Since == nil {
|
||||
out.Since = new(Timestamp)
|
||||
}
|
||||
*out.Since = Timestamp(in.Int64())
|
||||
out.Since = Timestamp(in.Int64())
|
||||
}
|
||||
case "until":
|
||||
if in.IsNull() {
|
||||
in.Skip()
|
||||
out.Until = nil
|
||||
out.Until = 0
|
||||
} else {
|
||||
if out.Until == nil {
|
||||
out.Until = new(Timestamp)
|
||||
}
|
||||
*out.Until = Timestamp(in.Int64())
|
||||
out.Until = Timestamp(in.Int64())
|
||||
}
|
||||
case "limit":
|
||||
out.Limit = int(in.Int())
|
||||
@@ -211,7 +205,7 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
out.RawByte(']')
|
||||
}
|
||||
}
|
||||
if in.Since != nil {
|
||||
if in.Since != 0 {
|
||||
const prefix string = ",\"since\":"
|
||||
if first {
|
||||
first = false
|
||||
@@ -219,9 +213,9 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
} else {
|
||||
out.RawString(prefix)
|
||||
}
|
||||
out.Int64(int64(*in.Since))
|
||||
out.Int64(int64(in.Since))
|
||||
}
|
||||
if in.Until != nil {
|
||||
if in.Until != 0 {
|
||||
const prefix string = ",\"until\":"
|
||||
if first {
|
||||
first = false
|
||||
@@ -229,7 +223,7 @@ func easyjson4d398eaaEncodeGithubComNbdWtfGoNostr(out *jwriter.Writer, in Filter
|
||||
} else {
|
||||
out.RawString(prefix)
|
||||
}
|
||||
out.Int64(int64(*in.Until))
|
||||
out.Int64(int64(in.Until))
|
||||
}
|
||||
if in.Limit != 0 || in.LimitZero {
|
||||
const prefix string = ",\"limit\":"
|
||||
|
||||
10
helpers.go
10
helpers.go
@@ -132,16 +132,6 @@ func escapeString(dst []byte, s string) []byte {
|
||||
return dst
|
||||
}
|
||||
|
||||
func arePointerValuesEqual[V comparable](a *V, b *V) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
if a != nil && b != nil {
|
||||
return *a == *b
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func subIdToSerial(subId string) int64 {
|
||||
n := strings.Index(subId, ":")
|
||||
if n < 0 || n > len(subId) {
|
||||
|
||||
@@ -20,8 +20,8 @@ type KeySigner struct {
|
||||
|
||||
// NewPlainKeySigner creates a new KeySigner from a private key.
|
||||
// Returns an error if the private key is invalid.
|
||||
func NewPlainKeySigner(sec [32]byte) (KeySigner, error) {
|
||||
return KeySigner{sec, nostr.GetPublicKey(sec), xsync.NewMapOf[nostr.PubKey, [32]byte]()}, nil
|
||||
func NewPlainKeySigner(sec [32]byte) KeySigner {
|
||||
return KeySigner{sec, nostr.GetPublicKey(sec), xsync.NewMapOf[nostr.PubKey, [32]byte]()}
|
||||
}
|
||||
|
||||
// SignEvent signs the provided event with the signer's private key.
|
||||
|
||||
@@ -41,7 +41,7 @@ func (rl *Relay) handleDeleteRequest(ctx context.Context, evt nostr.Event) error
|
||||
Kinds: []nostr.Kind{nostr.Kind(kind)},
|
||||
Authors: []nostr.PubKey{author},
|
||||
Tags: nostr.TagMap{"d": []string{identifier}},
|
||||
Until: &evt.CreatedAt,
|
||||
Until: evt.CreatedAt,
|
||||
}
|
||||
default:
|
||||
continue
|
||||
|
||||
@@ -156,7 +156,7 @@ func ListenForMessages(
|
||||
for ie := range pool.SubscribeMany(ctx, ourRelays, nostr.Filter{
|
||||
Kinds: []nostr.Kind{nostr.KindGiftWrap},
|
||||
Tags: nostr.TagMap{"p": []string{pk.Hex()}},
|
||||
Since: &since,
|
||||
Since: since,
|
||||
}, nostr.SubscriptionOptions{Label: "mydms"}) {
|
||||
rumor, err := nip59.GiftUnwrap(
|
||||
ie.Event,
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
//
|
||||
// It returns -1 when the filter is not eligible for hyperloglog calculation.
|
||||
func HyperLogLogEventPubkeyOffsetForFilter(filter nostr.Filter) int {
|
||||
if filter.IDs != nil || filter.Since != nil || filter.Until != nil || filter.Authors != nil ||
|
||||
if filter.IDs != nil || filter.Since != 0 || filter.Until != 0 || filter.Authors != nil ||
|
||||
len(filter.Kinds) != 1 || filter.Search != "" || len(filter.Tags) != 1 {
|
||||
// obvious cases in which we won't bother to do hyperloglog stuff
|
||||
return -1
|
||||
|
||||
@@ -109,11 +109,10 @@ func NewBunker(
|
||||
}
|
||||
|
||||
go func() {
|
||||
now := nostr.Now()
|
||||
events := pool.SubscribeMany(ctx, relays, nostr.Filter{
|
||||
Tags: nostr.TagMap{"p": []string{clientPublicKey.Hex()}},
|
||||
Kinds: []nostr.Kind{nostr.KindNostrConnect},
|
||||
Since: &now,
|
||||
Since: nostr.Now(),
|
||||
LimitZero: true,
|
||||
}, nostr.SubscriptionOptions{
|
||||
Label: "bunker46client",
|
||||
|
||||
@@ -19,10 +19,7 @@ import (
|
||||
|
||||
func TestWallet(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
kr, err := keyer.NewPlainKeySigner(nostr.MustSecretKeyFromHex("040cbf11f24b080ad9d8669d7514d9f3b7b1f58e5a6dcb75549352b041656537"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
kr := keyer.NewPlainKeySigner(nostr.MustSecretKeyFromHex("040cbf11f24b080ad9d8669d7514d9f3b7b1f58e5a6dcb75549352b041656537"))
|
||||
|
||||
privateKey, _ := btcec.NewPrivateKey()
|
||||
|
||||
@@ -85,7 +82,7 @@ func TestWallet(t *testing.T) {
|
||||
|
||||
// wallet metadata event
|
||||
metaEvent := nostr.Event{}
|
||||
err = w.toEvent(ctx, kr, &metaEvent)
|
||||
err := w.toEvent(ctx, kr, &metaEvent)
|
||||
require.NoError(t, err)
|
||||
events = append(events, metaEvent)
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ func (pool *Pool) PaginatorWithInterval(
|
||||
) func(ctx context.Context, urls []string, filter Filter, opts SubscriptionOptions) chan RelayEvent {
|
||||
return func(ctx context.Context, urls []string, filter Filter, opts SubscriptionOptions) chan RelayEvent {
|
||||
nextUntil := Now()
|
||||
if filter.Until != nil {
|
||||
nextUntil = *filter.Until
|
||||
if filter.Until != 0 {
|
||||
nextUntil = filter.Until
|
||||
}
|
||||
|
||||
globalLimit := uint64(filter.Limit)
|
||||
@@ -29,7 +29,7 @@ func (pool *Pool) PaginatorWithInterval(
|
||||
defer close(globalCh)
|
||||
|
||||
for {
|
||||
filter.Until = &nextUntil
|
||||
filter.Until = nextUntil
|
||||
time.Sleep(interval)
|
||||
|
||||
keepGoing := false
|
||||
@@ -48,7 +48,7 @@ func (pool *Pool) PaginatorWithInterval(
|
||||
return
|
||||
}
|
||||
|
||||
if evt.CreatedAt < *filter.Until {
|
||||
if evt.CreatedAt < filter.Until {
|
||||
nextUntil = evt.CreatedAt
|
||||
}
|
||||
}
|
||||
|
||||
3
pool.go
3
pool.go
@@ -492,8 +492,7 @@ func (pool *Pool) subMany(
|
||||
// this means the connection was closed for weird reasons, like the server shut down
|
||||
// so we will update the filters here to include only events seem from now on
|
||||
// and try to reconnect until we succeed
|
||||
now := Now()
|
||||
filter.Since = &now
|
||||
filter.Since = Now()
|
||||
debugLogf("%s reconnecting because sub.Events is broken\n", nm)
|
||||
goto reconnect
|
||||
}
|
||||
|
||||
11
sdk/feeds.go
11
sdk/feeds.go
@@ -52,10 +52,10 @@ func (sys *System) StreamLiveFeed(
|
||||
|
||||
serial := 0
|
||||
|
||||
var since *nostr.Timestamp
|
||||
var since nostr.Timestamp
|
||||
if data, _ := sys.KVStore.Get(latestKey); data != nil {
|
||||
latest = decodeTimestamp(data)
|
||||
since = &latest
|
||||
since = latest
|
||||
}
|
||||
|
||||
filter := nostr.Filter{
|
||||
@@ -127,7 +127,7 @@ func (sys *System) FetchFeedPage(
|
||||
|
||||
if until > oldestTimestamp {
|
||||
// we can use our local database
|
||||
filter.Until = &until
|
||||
filter.Until = until
|
||||
|
||||
count := 0
|
||||
for evt := range sys.Store.QueryEvents(filter) {
|
||||
@@ -150,9 +150,8 @@ func (sys *System) FetchFeedPage(
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
fUntil := oldestTimestamp + 1
|
||||
filter.Until = &fUntil
|
||||
filter.Since = nil
|
||||
filter.Until = oldestTimestamp + 1
|
||||
filter.Since = 0
|
||||
for ie := range sys.Pool.FetchMany(ctx, relays, filter, nostr.SubscriptionOptions{
|
||||
Label: "feedpage",
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user