Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/pipeline/noteReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ export interface NoteItem {
}

export const fetchAllNotes = async (): Promise<NoteItem[]> => {
// Fetch all active folder IDs
const activeFolderIds = new Set<string>();
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'],
Expand All @@ -24,5 +38,8 @@ export const fetchAllNotes = async (): Promise<NoteItem[]> => {
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;
};
Loading