mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:30:45 +00:00
fix(ci): restore plugin-local whatsapp deps
This commit is contained in:
@@ -26,6 +26,11 @@ import {
|
||||
setTelegramThreadBindingMaxAgeBySessionKey,
|
||||
} from "./thread-bindings.js";
|
||||
|
||||
async function flushMicrotasks(): Promise<void> {
|
||||
await Promise.resolve();
|
||||
await new Promise<void>((resolve) => queueMicrotask(resolve));
|
||||
}
|
||||
|
||||
describe("telegram thread bindings", () => {
|
||||
let stateDirOverride: string | undefined;
|
||||
|
||||
@@ -361,7 +366,7 @@ describe("telegram thread bindings", () => {
|
||||
manager.touchConversation("-100200300:topic:100");
|
||||
|
||||
await __testing.resetTelegramThreadBindingsForTests();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await flushMicrotasks();
|
||||
expect(unhandled).toEqual([]);
|
||||
} finally {
|
||||
process.off("unhandledRejection", onUnhandledRejection);
|
||||
|
||||
@@ -15,18 +15,11 @@ function cacheKey(chatId: number | string, threadId: number | string): string {
|
||||
}
|
||||
|
||||
function evictOldest(): void {
|
||||
if (cache.size <= MAX_ENTRIES) {
|
||||
return;
|
||||
}
|
||||
let oldestKey: string | undefined;
|
||||
let oldestTime = Infinity;
|
||||
for (const [key, entry] of cache) {
|
||||
if (entry.updatedAt < oldestTime) {
|
||||
oldestTime = entry.updatedAt;
|
||||
oldestKey = key;
|
||||
while (cache.size > MAX_ENTRIES) {
|
||||
const oldestKey = cache.keys().next().value;
|
||||
if (!oldestKey) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (oldestKey) {
|
||||
cache.delete(oldestKey);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +41,7 @@ export function updateTopicName(
|
||||
if (!merged.name) {
|
||||
return;
|
||||
}
|
||||
cache.delete(key);
|
||||
cache.set(key, merged);
|
||||
evictOldest();
|
||||
}
|
||||
@@ -56,9 +50,16 @@ export function getTopicName(
|
||||
chatId: number | string,
|
||||
threadId: number | string,
|
||||
): string | undefined {
|
||||
const entry = cache.get(cacheKey(chatId, threadId));
|
||||
const key = cacheKey(chatId, threadId);
|
||||
const entry = cache.get(key);
|
||||
if (entry) {
|
||||
entry.updatedAt = Date.now();
|
||||
const refreshedEntry: TopicEntry = {
|
||||
...entry,
|
||||
updatedAt: Date.now(),
|
||||
};
|
||||
cache.delete(key);
|
||||
cache.set(key, refreshedEntry);
|
||||
return refreshedEntry.name;
|
||||
}
|
||||
return entry?.name;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user