WithCheckDuplicateReplaceable() and helper functions for efficient replaceable event matching.

This commit is contained in:
fiatjaf
2025-03-12 00:19:41 -03:00
parent d2ceac48f6
commit 441f94563f
4 changed files with 88 additions and 4 deletions

View File

@@ -33,10 +33,14 @@ type Subscription struct {
// Context will be .Done() when the subscription ends
Context context.Context
// if it is not nil, CheckDuplicate will be called for every event received
// if it is not nil, checkDuplicate will be called for every event received
// if it returns true that event will not be processed further.
checkDuplicate func(id string, relay string) bool
// if it is not nil, checkDuplicateReplaceable will be called for every event received
// if it returns true that event will not be processed further.
checkDuplicateReplaceable func(d string, ts Timestamp) bool
match func(*Event) bool // this will be either Filters.Match or Filters.MatchIgnoringTimestampConstraints
live atomic.Bool
eosed atomic.Bool
@@ -63,9 +67,15 @@ type WithCheckDuplicate func(id, relay string) bool
func (_ WithCheckDuplicate) IsSubscriptionOption() {}
// WithCheckDuplicateReplaceable sets checkDuplicateReplaceable on the subscription
type WithCheckDuplicateReplaceable func(d string, ts Timestamp) bool
func (_ WithCheckDuplicateReplaceable) IsSubscriptionOption() {}
var (
_ SubscriptionOption = (WithLabel)("")
_ SubscriptionOption = (WithCheckDuplicate)(nil)
_ SubscriptionOption = (WithCheckDuplicateReplaceable)(nil)
)
func (sub *Subscription) start() {