Skip to content

Commit 696e6e2

Browse files
committed
inbox: fix concurrent map writes, this time it should work.
1 parent d41cc27 commit 696e6e2

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

inbox/wot.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/FastFilter/xorfilter"
1313
"github.com/fiatjaf/pyramid/global"
1414
"github.com/fiatjaf/pyramid/pyramid"
15+
"github.com/puzpuzpuz/xsync/v3"
1516
"golang.org/x/sync/semaphore"
1617
)
1718

@@ -37,7 +38,7 @@ func computeAggregatedWoT(ctx context.Context) (WotXorFilter, error) {
3738
members = append(members, k)
3839
}
3940

40-
queue := make(map[nostr.PubKey]struct{}, len(members)*100)
41+
queue := xsync.NewMapOf[nostr.PubKey, struct{}](xsync.WithPresize(len(members) * 200))
4142
wg := sync.WaitGroup{}
4243
sem := semaphore.NewWeighted(15)
4344

@@ -57,7 +58,7 @@ func computeAggregatedWoT(ctx context.Context) (WotXorFilter, error) {
5758
continue
5859
}
5960

60-
queue[f.Pubkey] = struct{}{}
61+
queue.Store(f.Pubkey, struct{}{})
6162
}
6263
})
6364
}
@@ -66,8 +67,8 @@ func computeAggregatedWoT(ctx context.Context) (WotXorFilter, error) {
6667

6768
res := make(chan nostr.PubKey)
6869

69-
log.Info().Int("n", len(queue)).Msg("fetching secondary follow lists for follows")
70-
for user := range queue {
70+
log.Info().Int("n", queue.Size()).Msg("fetching secondary follow lists for follows")
71+
for user := range queue.Range {
7172
if err := sem.Acquire(ctx, 1); err != nil {
7273
return WotXorFilter{}, fmt.Errorf("failed to acquire: %w", err)
7374
}

0 commit comments

Comments
 (0)