mirror of
https://github.com/aljazceru/crawler_v2.git
synced 2025-12-17 15:34:26 +01:00
added parameter for cache capacity
This commit is contained in:
@@ -174,6 +174,12 @@ func LoadConfig() (*Config, error) {
|
|||||||
}
|
}
|
||||||
config.Arbiter.PromotionWait = time.Duration(wait) * time.Second
|
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":
|
case "PROCESSOR_PRINT_EVERY":
|
||||||
config.Processor.PrintEvery, err = strconv.Atoi(val)
|
config.Processor.PrintEvery, err = strconv.Atoi(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -18,15 +18,19 @@ import (
|
|||||||
var ErrUnsupportedKind = errors.New("unsupported event kind")
|
var ErrUnsupportedKind = errors.New("unsupported event kind")
|
||||||
|
|
||||||
type ProcessorConfig struct {
|
type ProcessorConfig struct {
|
||||||
|
CacheCapacity int
|
||||||
PrintEvery int
|
PrintEvery int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProcessorConfig() ProcessorConfig {
|
func NewProcessorConfig() ProcessorConfig {
|
||||||
return ProcessorConfig{PrintEvery: 5000}
|
return ProcessorConfig{
|
||||||
|
CacheCapacity: 10000,
|
||||||
|
PrintEvery: 5000}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c ProcessorConfig) Print() {
|
func (c ProcessorConfig) Print() {
|
||||||
fmt.Printf("Processor\n")
|
fmt.Printf("Processor\n")
|
||||||
|
fmt.Printf(" CacheCapacity: %d\n", c.CacheCapacity)
|
||||||
fmt.Printf(" PrintEvery: %d\n", c.PrintEvery)
|
fmt.Printf(" PrintEvery: %d\n", c.PrintEvery)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +45,7 @@ func Processor(
|
|||||||
var processed int
|
var processed int
|
||||||
|
|
||||||
cache := walks.NewWalker(
|
cache := walks.NewWalker(
|
||||||
walks.WithCapacity(10000),
|
walks.WithCapacity(config.CacheCapacity),
|
||||||
walks.WithFallback(db),
|
walks.WithFallback(db),
|
||||||
walks.WithLogFile("cache.log"),
|
walks.WithLogFile("cache.log"),
|
||||||
)
|
)
|
||||||
@@ -60,7 +64,7 @@ func Processor(
|
|||||||
err = processFollowList(cache, db, event)
|
err = processFollowList(cache, db, event)
|
||||||
|
|
||||||
case nostr.KindProfileMetadata:
|
case nostr.KindProfileMetadata:
|
||||||
err = nil //HandleProfileMetadata(eventStore, event)
|
err = nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = ErrUnsupportedKind
|
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 {
|
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()
|
defer cancel()
|
||||||
|
|
||||||
author, err := db.NodeByKey(ctx, event.PubKey)
|
author, err := db.NodeByKey(ctx, event.PubKey)
|
||||||
@@ -137,11 +144,7 @@ const (
|
|||||||
maxFollows = 50000
|
maxFollows = 50000
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParsePubkeys returns the slice of pubkeys that are correctly listed in the nostr.Tags.
|
// parse unique pubkeys (excluding author) from the "p" tags in the event.
|
||||||
// - 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
|
|
||||||
func parsePubkeys(event *nostr.Event) []string {
|
func parsePubkeys(event *nostr.Event) []string {
|
||||||
pubkeys := make([]string, 0, min(len(event.Tags), maxFollows))
|
pubkeys := make([]string, 0, min(len(event.Tags), maxFollows))
|
||||||
for _, tag := range event.Tags {
|
for _, tag := range event.Tags {
|
||||||
|
|||||||
Reference in New Issue
Block a user