mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-08-03 16:32:10 +02:00
after getting an EOSE we should stop checking since/until.
This commit is contained in:
33
filter.go
33
filter.go
@@ -39,12 +39,37 @@ func (eff Filters) Match(event *Event) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (eff Filters) MatchIgnoringTimestampConstraints(event *Event) bool {
|
||||||
|
for _, filter := range eff {
|
||||||
|
if filter.MatchesIgnoringTimestampConstraints(event) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (ef Filter) String() string {
|
func (ef Filter) String() string {
|
||||||
j, _ := easyjson.Marshal(ef)
|
j, _ := easyjson.Marshal(ef)
|
||||||
return string(j)
|
return string(j)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ef Filter) Matches(event *Event) bool {
|
func (ef Filter) Matches(event *Event) bool {
|
||||||
|
if !ef.MatchesIgnoringTimestampConstraints(event) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if ef.Since != nil && event.CreatedAt < *ef.Since {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if ef.Until != nil && event.CreatedAt > *ef.Until {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ef Filter) MatchesIgnoringTimestampConstraints(event *Event) bool {
|
||||||
if event == nil {
|
if event == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -67,14 +92,6 @@ func (ef Filter) Matches(event *Event) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ef.Since != nil && event.CreatedAt < *ef.Since {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
if ef.Until != nil && event.CreatedAt > *ef.Until {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
relay.go
1
relay.go
@@ -397,6 +397,7 @@ func (r *Relay) PrepareSubscription(ctx context.Context, filters Filters, opts .
|
|||||||
EndOfStoredEvents: make(chan struct{}, 1),
|
EndOfStoredEvents: make(chan struct{}, 1),
|
||||||
ClosedReason: make(chan string, 1),
|
ClosedReason: make(chan string, 1),
|
||||||
Filters: filters,
|
Filters: filters,
|
||||||
|
match: filters.Match,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
|
@@ -32,6 +32,7 @@ type Subscription struct {
|
|||||||
// Context will be .Done() when the subscription ends
|
// Context will be .Done() when the subscription ends
|
||||||
Context context.Context
|
Context context.Context
|
||||||
|
|
||||||
|
match func(*Event) bool // this will be either Filters.Match or Filters.MatchIgnoringTimestampConstraints
|
||||||
live atomic.Bool
|
live atomic.Bool
|
||||||
eosed atomic.Bool
|
eosed atomic.Bool
|
||||||
closed atomic.Bool
|
closed atomic.Bool
|
||||||
@@ -104,6 +105,7 @@ func (sub *Subscription) dispatchEvent(evt *Event) {
|
|||||||
|
|
||||||
func (sub *Subscription) dispatchEose() {
|
func (sub *Subscription) dispatchEose() {
|
||||||
if sub.eosed.CompareAndSwap(false, true) {
|
if sub.eosed.CompareAndSwap(false, true) {
|
||||||
|
sub.match = sub.Filters.MatchIgnoringTimestampConstraints
|
||||||
go func() {
|
go func() {
|
||||||
sub.storedwg.Wait()
|
sub.storedwg.Wait()
|
||||||
sub.EndOfStoredEvents <- struct{}{}
|
sub.EndOfStoredEvents <- struct{}{}
|
||||||
|
Reference in New Issue
Block a user