allow custom CheckDuplicate in pool subscriptions.

This commit is contained in:
fiatjaf
2025-05-02 15:19:16 -03:00
parent b7989084f2
commit 002dc1e84d

View File

@@ -246,6 +246,7 @@ func (pool *Pool) FetchMany(
) chan RelayEvent {
seenAlready := xsync.NewMapOf[ID, struct{}]()
if opts.CheckDuplicate == nil {
opts.CheckDuplicate = func(id ID, relay string) bool {
_, exists := seenAlready.LoadOrStore(id, struct{}{})
if exists && pool.duplicateMiddleware != nil {
@@ -253,6 +254,7 @@ func (pool *Pool) FetchMany(
}
return exists
}
}
return pool.subManyEoseNonOverwriteCheckDuplicate(ctx, urls, filter, opts)
}
@@ -393,6 +395,7 @@ func (pool *Pool) subMany(
}()
}
if opts.CheckDuplicate == nil {
opts.CheckDuplicate = func(id ID, relay string) bool {
_, exists := seenAlready.Load(id)
if exists && pool.duplicateMiddleware != nil {
@@ -400,6 +403,7 @@ func (pool *Pool) subMany(
}
return exists
}
}
pending := xsync.NewCounter()
pending.Add(int64(len(urls)))
@@ -691,6 +695,7 @@ func (pool *Pool) BatchedSubManyEose(
wg.Add(len(dfs))
seenAlready := xsync.NewMapOf[ID, struct{}]()
if opts.CheckDuplicate == nil {
opts.CheckDuplicate = func(id ID, relay string) bool {
_, exists := seenAlready.LoadOrStore(id, struct{}{})
if exists && pool.duplicateMiddleware != nil {
@@ -698,6 +703,7 @@ func (pool *Pool) BatchedSubManyEose(
}
return exists
}
}
for _, df := range dfs {
go func(df DirectedFilter) {