avoid overflow if there is no logger

This commit is contained in:
pippellia-btc
2025-06-23 18:42:44 +02:00
parent a24c739a41
commit 8f630f0bfb

View File

@@ -125,8 +125,8 @@ func (c *CachedWalker) logStats() {
if c.log != nil { if c.log != nil {
hitRatio := 100 * float64(c.hits) / float64(c.calls) hitRatio := 100 * float64(c.hits) / float64(c.calls)
c.log.Printf("calls %d, hits %f%%", c.calls, hitRatio) c.log.Printf("calls %d, hits %f%%", c.calls, hitRatio)
c.calls, c.hits = 0, 0
} }
c.calls, c.hits = 0, 0
} }
func (c *CachedWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) { func (c *CachedWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID, error) {
@@ -136,7 +136,7 @@ func (c *CachedWalker) Follows(ctx context.Context, node graph.ID) ([]graph.ID,
} }
c.calls++ c.calls++
if c.calls >= 1000_000 { if c.calls >= 1_000_000 {
defer c.logStats() defer c.logStats()
} }