Tasks linked to notes are public but inefficient
This commit is contained in:
+9
-8
@@ -590,6 +590,12 @@ const dedupeNoteRefs = (refs: NoteRef[]) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const runDailyCleanupIfNeeded = () => {
|
||||||
|
const today = new Date().toLocaleDateString('en-CA');
|
||||||
|
if (store.lastCompletedTaskCleanupDate === today) return;
|
||||||
|
setStore("lastCompletedTaskCleanupDate", today);
|
||||||
|
};
|
||||||
|
|
||||||
const recordHasField = (record: any, field: string) =>
|
const recordHasField = (record: any, field: string) =>
|
||||||
!!record && Object.prototype.hasOwnProperty.call(record, field);
|
!!record && Object.prototype.hasOwnProperty.call(record, field);
|
||||||
|
|
||||||
@@ -3066,15 +3072,10 @@ export const loadTasksLinkedToNote = async (note: Pick<Note, "id" | "key" | "tit
|
|||||||
|
|
||||||
const noteTag = buildNoteTag(note.key || note.title);
|
const noteTag = buildNoteTag(note.key || note.title);
|
||||||
const escapedNoteTag = noteTag.replace(/"/g, '\\"');
|
const escapedNoteTag = noteTag.replace(/"/g, '\\"');
|
||||||
const escapedNoteIdNeedle = `\\"noteId\\":\\"${note.id}\\"`;
|
|
||||||
const escapedNoteKeyNeedle = note.key ? `\\"key\\":\\"${note.key.replace(/"/g, '\\"')}\\"` : "";
|
|
||||||
const linkedTaskIds = [...new Set((note.tasks || []).filter(Boolean))];
|
const linkedTaskIds = [...new Set((note.tasks || []).filter(Boolean))];
|
||||||
const idFilter = linkedTaskIds.length > 0
|
const idFilter = linkedTaskIds.length > 0
|
||||||
? ` || (${linkedTaskIds.map(taskId => `id = "${taskId}"`).join(" || ")})`
|
? ` || (${linkedTaskIds.map(taskId => `id = "${taskId}"`).join(" || ")})`
|
||||||
: "";
|
: "";
|
||||||
const noteRefsFilter = escapedNoteKeyNeedle
|
|
||||||
? `(noteRefs ~ "${escapedNoteIdNeedle}" || noteRefs ~ "${escapedNoteKeyNeedle}")`
|
|
||||||
: `(noteRefs ~ "${escapedNoteIdNeedle}")`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const idFetchResults = await Promise.allSettled(
|
const idFetchResults = await Promise.allSettled(
|
||||||
@@ -3090,7 +3091,7 @@ export const loadTasksLinkedToNote = async (note: Pick<Note, "id" | "key" | "tit
|
|||||||
.map(result => result.value);
|
.map(result => result.value);
|
||||||
|
|
||||||
const listRecords = await pb.collection(TASGRID_COLLECTION).getFullList({
|
const listRecords = await pb.collection(TASGRID_COLLECTION).getFullList({
|
||||||
filter: `((tags ~ "${escapedNoteTag}") || ${noteRefsFilter}${idFilter}) && !tags ~ "__template__"`,
|
filter: `((tags ~ "${escapedNoteTag}")${idFilter}) && tags !~ "__template__"`,
|
||||||
sort: "-updated",
|
sort: "-updated",
|
||||||
fields: getTaskListFields(),
|
fields: getTaskListFields(),
|
||||||
requestKey: `note-linked-${note.id}`
|
requestKey: `note-linked-${note.id}`
|
||||||
@@ -3117,8 +3118,8 @@ export const loadTasksLinkedToNote = async (note: Pick<Note, "id" | "key" | "tit
|
|||||||
});
|
});
|
||||||
return Array.from(taskMap.values());
|
return Array.from(taskMap.values());
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
console.error("Failed to load note-linked tasks:", err);
|
console.error("Failed to load note-linked tasks:", err?.status, err?.response || err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user