allow custom CheckDuplicate in pool subscriptions.
This commit is contained in:
@@ -246,12 +246,14 @@ func (pool *Pool) FetchMany(
|
|||||||
) chan RelayEvent {
|
) chan RelayEvent {
|
||||||
seenAlready := xsync.NewMapOf[ID, struct{}]()
|
seenAlready := xsync.NewMapOf[ID, struct{}]()
|
||||||
|
|
||||||
opts.CheckDuplicate = func(id ID, relay string) bool {
|
if opts.CheckDuplicate == nil {
|
||||||
_, exists := seenAlready.LoadOrStore(id, struct{}{})
|
opts.CheckDuplicate = func(id ID, relay string) bool {
|
||||||
if exists && pool.duplicateMiddleware != nil {
|
_, exists := seenAlready.LoadOrStore(id, struct{}{})
|
||||||
pool.duplicateMiddleware(relay, id)
|
if exists && pool.duplicateMiddleware != nil {
|
||||||
|
pool.duplicateMiddleware(relay, id)
|
||||||
|
}
|
||||||
|
return exists
|
||||||
}
|
}
|
||||||
return exists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pool.subManyEoseNonOverwriteCheckDuplicate(ctx, urls, filter, opts)
|
return pool.subManyEoseNonOverwriteCheckDuplicate(ctx, urls, filter, opts)
|
||||||
@@ -393,12 +395,14 @@ func (pool *Pool) subMany(
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.CheckDuplicate = func(id ID, relay string) bool {
|
if opts.CheckDuplicate == nil {
|
||||||
_, exists := seenAlready.Load(id)
|
opts.CheckDuplicate = func(id ID, relay string) bool {
|
||||||
if exists && pool.duplicateMiddleware != nil {
|
_, exists := seenAlready.Load(id)
|
||||||
pool.duplicateMiddleware(relay, id)
|
if exists && pool.duplicateMiddleware != nil {
|
||||||
|
pool.duplicateMiddleware(relay, id)
|
||||||
|
}
|
||||||
|
return exists
|
||||||
}
|
}
|
||||||
return exists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pending := xsync.NewCounter()
|
pending := xsync.NewCounter()
|
||||||
@@ -691,12 +695,14 @@ func (pool *Pool) BatchedSubManyEose(
|
|||||||
wg.Add(len(dfs))
|
wg.Add(len(dfs))
|
||||||
seenAlready := xsync.NewMapOf[ID, struct{}]()
|
seenAlready := xsync.NewMapOf[ID, struct{}]()
|
||||||
|
|
||||||
opts.CheckDuplicate = func(id ID, relay string) bool {
|
if opts.CheckDuplicate == nil {
|
||||||
_, exists := seenAlready.LoadOrStore(id, struct{}{})
|
opts.CheckDuplicate = func(id ID, relay string) bool {
|
||||||
if exists && pool.duplicateMiddleware != nil {
|
_, exists := seenAlready.LoadOrStore(id, struct{}{})
|
||||||
pool.duplicateMiddleware(relay, id)
|
if exists && pool.duplicateMiddleware != nil {
|
||||||
|
pool.duplicateMiddleware(relay, id)
|
||||||
|
}
|
||||||
|
return exists
|
||||||
}
|
}
|
||||||
return exists
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, df := range dfs {
|
for _, df := range dfs {
|
||||||
|
|||||||
Reference in New Issue
Block a user