fix locking on generic list and set fetching, decrease dataloader batch size, test.

This commit is contained in:
fiatjaf
2025-01-17 17:39:24 -03:00
parent 3e1c0ddc7e
commit 3fd33ce281
7 changed files with 83 additions and 26 deletions

View File

@ -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