From 36420f35bde54998d09df1c931a2be2b65ca37a0 Mon Sep 17 00:00:00 2001 From: Harsh16gupta Date: Wed, 8 Jul 2026 19:42:55 +0530 Subject: [PATCH] fix: ignore notes belonging to deleted notebooks --- src/pipeline/noteReader.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/pipeline/noteReader.ts b/src/pipeline/noteReader.ts index fe8a138..a89d5fc 100644 --- a/src/pipeline/noteReader.ts +++ b/src/pipeline/noteReader.ts @@ -10,9 +10,23 @@ export interface NoteItem { } export const fetchAllNotes = async (): Promise => { + // Fetch all active folder IDs + const activeFolderIds = new Set(); + let folderPage = 1; + while (true) { + const result = await joplin.data.get(['folders'], { + fields: ['id'], + page: folderPage, + limit: 50, + }); + result.items.forEach((f: any) => activeFolderIds.add(f.id)); + if (!result.has_more) break; + folderPage++; + } + + // Fetch all notes let page = 1; const allNotes: NoteItem[] = []; - while (true) { const result = await joplin.data.get(['notes'], { fields: ['id', 'title', 'body', 'updated_time', 'user_updated_time', 'parent_id'], @@ -24,5 +38,8 @@ export const fetchAllNotes = async (): Promise => { page++; } - return allNotes; + // Filter out notes whose parent folder no longer exists (orphaned/deleted folders) + const activeNotes = allNotes.filter((note) => activeFolderIds.has(note.parent_id)); + + return activeNotes; };