From 7ed167ae84fd3e0aa9d8a7bb627b0d7f963e8ea0 Mon Sep 17 00:00:00 2001 From: pippellia-btc Date: Thu, 5 Jun 2025 17:51:50 +0200 Subject: [PATCH] added parameter for cache capacity --- cmd/config.go | 6 ++++++ pkg/pipe/processor.go | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index a4ecbcd..78b3e98 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -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 { diff --git a/pkg/pipe/processor.go b/pkg/pipe/processor.go index b13e082..1cf7d12 100644 --- a/pkg/pipe/processor.go +++ b/pkg/pipe/processor.go @@ -18,15 +18,19 @@ import ( var ErrUnsupportedKind = errors.New("unsupported event kind") type ProcessorConfig struct { - PrintEvery int + 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 {