added parameter for cache capacity

This commit is contained in:
pippellia-btc
2025-06-05 17:51:50 +02:00
parent d924310bbd
commit 7ed167ae84
2 changed files with 19 additions and 10 deletions

View File

@@ -174,6 +174,12 @@ func LoadConfig() (*Config, error) {
}
config.Arbiter.PromotionWait = time.Duration(wait) * time.Second
case "PROCESSOR_CACHE_CAPACITY":
config.Processor.CacheCapacity, err = strconv.Atoi(val)
if err != nil {
return nil, fmt.Errorf("error parsing %v: %v", keyVal, err)
}
case "PROCESSOR_PRINT_EVERY":
config.Processor.PrintEvery, err = strconv.Atoi(val)
if err != nil {

View File

@@ -18,15 +18,19 @@ import (
var ErrUnsupportedKind = errors.New("unsupported event kind")
type ProcessorConfig struct {
CacheCapacity int
PrintEvery int
}
func NewProcessorConfig() ProcessorConfig {
return ProcessorConfig{PrintEvery: 5000}
return ProcessorConfig{
CacheCapacity: 10000,
PrintEvery: 5000}
}
func (c ProcessorConfig) Print() {
fmt.Printf("Processor\n")
fmt.Printf(" CacheCapacity: %d\n", c.CacheCapacity)
fmt.Printf(" PrintEvery: %d\n", c.PrintEvery)
}
@@ -41,7 +45,7 @@ func Processor(
var processed int
cache := walks.NewWalker(
walks.WithCapacity(10000),
walks.WithCapacity(config.CacheCapacity),
walks.WithFallback(db),
walks.WithLogFile("cache.log"),
)
@@ -60,7 +64,7 @@ func Processor(
err = processFollowList(cache, db, event)
case nostr.KindProfileMetadata:
err = nil //HandleProfileMetadata(eventStore, event)
err = nil
default:
err = ErrUnsupportedKind
@@ -78,8 +82,11 @@ func Processor(
}
}
// processFollowList parses the pubkeys listed in the event, and uses them to:
// - update the follows of the author (db and cache)
// - update the author's random walks and signal the number to the [WalksTracker]
func processFollowList(cache *walks.CachedWalker, db redb.RedisDB, event *nostr.Event) error {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
author, err := db.NodeByKey(ctx, event.PubKey)
@@ -137,11 +144,7 @@ const (
maxFollows = 50000
)
// ParsePubkeys returns the slice of pubkeys that are correctly listed in the nostr.Tags.
// - Badly formatted tags are ignored.
// - Pubkeys will be uniquely added (no repetitions).
// - The author of the event will be removed from the followed pubkeys if present.
// - NO CHECKING the validity of the pubkeys
// parse unique pubkeys (excluding author) from the "p" tags in the event.
func parsePubkeys(event *nostr.Event) []string {
pubkeys := make([]string, 0, min(len(event.Tags), maxFollows))
for _, tag := range event.Tags {