Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

Fix resource cleanup when deleting memos

yoma1670b2f6fb2f
diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts
index b2e49e94..822c941b 100644
--- a/apps/api/src/index.ts
+++ b/apps/api/src/index.ts
@@ -1598,6 +1598,11 @@ app.delete("/api/v1/memos/:id", async (c) => {
SET is_deleted = 1, deleted_at = ?, updated_at = ?
WHERE id = ? AND is_deleted = 0`
).bind(now, now, id),
+ c.env.DB.prepare(
+ `UPDATE resources
+ SET is_deleted = 1, deleted_at = ?, updated_at = ?
+ WHERE memo_id = ? AND is_deleted = 0`
+ ).bind(now, now, id),
c.env.DB.prepare(`DELETE FROM memos_fts WHERE memo_id = ?`).bind(id),
auditStatement(c.env.DB, actor.actorType, actor.actorId, "memo.delete", "memo", id, {}),
]);
@@ -1635,6 +1640,11 @@ app.post("/api/v1/memos/:id/restore", async (c) => {
SET notebook_id = ?, is_deleted = 0, deleted_at = NULL, updated_at = ?
WHERE id = ? AND is_deleted = 1`
).bind(restoreNotebookId, now, id),
+ c.env.DB.prepare(
+ `UPDATE resources
+ SET is_deleted = 0, deleted_at = NULL, updated_at = ?
+ WHERE memo_id = ? AND is_deleted = 1`
+ ).bind(now, id),
c.env.DB.prepare(`DELETE FROM memos_fts WHERE memo_id = ?`).bind(id),
c.env.DB.prepare(
`INSERT INTO memos_fts (memo_id, title, content_text, tags)
@@ -3282,6 +3292,13 @@ const deleteMemosRecord = async (
WHERE is_deleted = 0 AND id IN (${placeholders})`
)
.bind(now, now, ...uniqueMemoIds),
+ db
+ .prepare(
+ `UPDATE resources
+ SET is_deleted = 1, deleted_at = ?, updated_at = ?
+ WHERE is_deleted = 0 AND memo_id IN (${placeholders})`
+ )
+ .bind(now, now, ...uniqueMemoIds),
db.prepare(`DELETE FROM memos_fts WHERE memo_id IN (${placeholders})`).bind(...uniqueMemoIds)
);
diff --git a/apps/web/src/components/WorkspaceApp.tsx b/apps/web/src/components/WorkspaceApp.tsx
index 8ee0c062..b241162f 100644
--- a/apps/web/src/components/WorkspaceApp.tsx
+++ b/apps/web/src/components/WorkspaceApp.tsx
@@ -1389,7 +1389,7 @@ export const WorkspaceApp = ({
queryClient.invalidateQueries({ queryKey: ["memos"], refetchType }),
queryClient.invalidateQueries({ queryKey: ["memo"], refetchType }),
queryClient.invalidateQueries({ queryKey: ["notebooks"], refetchType }),
- queryClient.invalidateQueries({ queryKey: ["resources"], refetchType: "inactive" }),
+ queryClient.invalidateQueries({ queryKey: ["resources"], refetchType: _error ? "active" : "all" }),
]);
},
});
@@ -1440,7 +1440,7 @@ export const WorkspaceApp = ({
void Promise.all([
queryClient.invalidateQueries({ queryKey: ["memos"], refetchType }),
queryClient.invalidateQueries({ queryKey: ["notebooks"], refetchType }),
- queryClient.invalidateQueries({ queryKey: ["resources"], refetchType: "inactive" }),
+ queryClient.invalidateQueries({ queryKey: ["resources"], refetchType: _error ? "active" : "all" }),
]);
},
});
@@ -1469,6 +1469,7 @@ export const WorkspaceApp = ({
void Promise.all([
queryClient.invalidateQueries({ queryKey: ["memos"] }),
queryClient.invalidateQueries({ queryKey: ["notebooks"] }),
+ queryClient.invalidateQueries({ queryKey: ["resources"], refetchType: "all" }),
]);
setSelectedNotebookId(data.memo.notebookId);
navigateWorkspaceHome();