mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:54:58 +00:00
Cron+Slack: fix cooldown omission and cache cap enforcement
This commit is contained in:
@@ -55,4 +55,13 @@ describe("slack sent-thread-cache", () => {
|
||||
vi.spyOn(Date, "now").mockReturnValue(Date.now() + 25 * 60 * 60 * 1000);
|
||||
expect(hasSlackThreadParticipation("A1", "C123", "1700000000.000001")).toBe(false);
|
||||
});
|
||||
|
||||
it("enforces maximum entries by evicting oldest fresh entries", () => {
|
||||
for (let i = 0; i < 5001; i += 1) {
|
||||
recordSlackThreadParticipation("A1", "C123", `1700000000.${String(i).padStart(6, "0")}`);
|
||||
}
|
||||
|
||||
expect(hasSlackThreadParticipation("A1", "C123", "1700000000.000000")).toBe(false);
|
||||
expect(hasSlackThreadParticipation("A1", "C123", "1700000000.005000")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,6 +22,13 @@ function evictExpired(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function evictOldest(): void {
|
||||
const oldest = threadParticipation.keys().next().value;
|
||||
if (oldest) {
|
||||
threadParticipation.delete(oldest);
|
||||
}
|
||||
}
|
||||
|
||||
export function recordSlackThreadParticipation(
|
||||
accountId: string,
|
||||
channelId: string,
|
||||
@@ -33,6 +40,9 @@ export function recordSlackThreadParticipation(
|
||||
if (threadParticipation.size >= MAX_ENTRIES) {
|
||||
evictExpired();
|
||||
}
|
||||
if (threadParticipation.size >= MAX_ENTRIES) {
|
||||
evictOldest();
|
||||
}
|
||||
threadParticipation.set(makeKey(accountId, channelId, threadTs), Date.now());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user