From 10c6bf50dfbb7a613d29792472c507e7478a4334 Mon Sep 17 00:00:00 2001 From: ewood Date: Sun, 8 Feb 2026 18:46:06 -0500 Subject: [PATCH] Refactor listThreadIds to ensure saver is initialized and improve PostgreSQL query efficiency --- src/ai/memory/checkpoint-memory.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ai/memory/checkpoint-memory.ts b/src/ai/memory/checkpoint-memory.ts index f793eb3..c0427d5 100644 --- a/src/ai/memory/checkpoint-memory.ts +++ b/src/ai/memory/checkpoint-memory.ts @@ -155,12 +155,12 @@ export async function listThreadIds(graphType: string): Promise { await initialize(); const db = await getOrCreateDatabase(graphType); + const saver = await getSaver('list-threads', graphType); // Ensure saver is initialized const ids = new Set(); - if (db.backend === "postgres" && db.sharedSaver) { + if (db.backend === "postgres") { // For PostgreSQL: query distinct thread_ids directly (much more efficient than loading checkpoints) - const postgresaver = db.sharedSaver as PostgresSaver; - const pool = (postgresaver as any).pool as Pool; + const pool = (saver as any).pool as Pool; const result = await pool.query( 'SELECT DISTINCT thread_id FROM checkpoints ORDER BY thread_id' ); @@ -169,7 +169,6 @@ export async function listThreadIds(graphType: string): Promise { } } else { // For SQLite: use limited checkpoint list - const saver = await getSaver('list-threads', graphType); for await (const checkpoint of saver.list({}, { limit: 100 })) { const threadId = checkpoint.config?.configurable?.thread_id; if (threadId) {