mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-09 23:59:54 +02:00
fix locking on generic list and set fetching, decrease dataloader batch size, test.
This commit is contained in:
@ -3,6 +3,7 @@ package sdk
|
||||
import (
|
||||
"context"
|
||||
"slices"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
@ -27,10 +28,8 @@ func fetchGenericSets[I TagItemWithValue](
|
||||
parseTag func(nostr.Tag) (I, bool),
|
||||
cache cache.Cache32[GenericSets[I]],
|
||||
) (fl GenericSets[I], fromInternal bool) {
|
||||
// we have 24 mutexes, so we can load up to 24 lists at the same time, but if we do the same exact
|
||||
// call that will do it only once, the subsequent ones will wait for a result to be cached
|
||||
// and then return it from cache -- 13 is an arbitrary index for the pubkey
|
||||
lockIdx := (int(pubkey[13]) + int(addressableIndex)) % 24
|
||||
n, _ := strconv.ParseUint(pubkey[14:16], 16, 8)
|
||||
lockIdx := (n + uint64(actualKind)) % 60
|
||||
genericListMutexes[lockIdx].Lock()
|
||||
|
||||
if valueWasJustCached[lockIdx] {
|
||||
@ -40,7 +39,7 @@ func fetchGenericSets[I TagItemWithValue](
|
||||
time.Sleep(time.Millisecond * 10)
|
||||
}
|
||||
|
||||
defer genericListMutexes[lockIdx].Unlock()
|
||||
genericListMutexes[lockIdx].Unlock()
|
||||
|
||||
if v, ok := cache.Get(pubkey); ok {
|
||||
return v, true
|
||||
|
Reference in New Issue
Block a user