fix(nostr): bound seen tracker capacity · openclaw/openclaw@5b0036f
steipete
·
2026-05-31
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -167,6 +167,19 @@ describe("SeenTracker", () => {
|
167 | 167 | |
168 | 168 | tracker.stop(); |
169 | 169 | }); |
| 170 | + |
| 171 | +it("keeps non-positive capacities usable", () => { |
| 172 | +const tracker = createTracker({ maxEntries: 0 }); |
| 173 | + |
| 174 | +tracker.add("id1"); |
| 175 | +tracker.add("id2"); |
| 176 | + |
| 177 | +expect(tracker.size()).toBe(1); |
| 178 | +expect(tracker.peek("id1")).toBe(false); |
| 179 | +expect(tracker.peek("id2")).toBe(true); |
| 180 | + |
| 181 | +tracker.stop(); |
| 182 | +}); |
170 | 183 | }); |
171 | 184 | |
172 | 185 | describe("TTL expiration", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,8 @@
|
3 | 3 | * Prevents unbounded memory growth under high load or abuse. |
4 | 4 | */ |
5 | 5 | |
| 6 | +import { resolveIntegerOption } from "openclaw/plugin-sdk/number-runtime"; |
| 7 | + |
6 | 8 | interface SeenTrackerOptions { |
7 | 9 | /** Maximum number of entries to track (default: 100,000) */ |
8 | 10 | maxEntries?: number; |
@@ -42,7 +44,7 @@ interface Entry {
|
42 | 44 | * Create a new seen tracker with LRU eviction and TTL expiration. |
43 | 45 | */ |
44 | 46 | export function createSeenTracker(options?: SeenTrackerOptions): SeenTracker { |
45 | | -const maxEntries = options?.maxEntries ?? 100_000; |
| 47 | +const maxEntries = resolveIntegerOption(options?.maxEntries, 100_000, { min: 1 }); |
46 | 48 | const ttlMs = options?.ttlMs ?? 60 * 60 * 1000; // 1 hour |
47 | 49 | const pruneIntervalMs = options?.pruneIntervalMs ?? 10 * 60 * 1000; // 10 minutes |
48 | 50 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。