From 39c3cea7635c3b8ab331deda647afe86427b02c3 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Mon, 9 Mar 2026 11:18:05 +0800 Subject: [PATCH] :art: Improve cleaning up unreferenced databases https://github.com/siyuan-note/siyuan/issues/11569#issuecomment-3884008188 (#17089) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 只有删除当前预览的数据库时才清空预览区 - 渲染数据库始终不创建新的 JSON 文件 --- app/src/config/image.ts | 31 ++++++++++++++++------------- app/src/constants.ts | 1 + app/src/protyle/render/av/render.ts | 1 + app/src/types/protyle.d.ts | 3 ++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/app/src/config/image.ts b/app/src/config/image.ts index be2f9f662..8da9e862f 100644 --- a/app/src/config/image.ts +++ b/app/src/config/image.ts @@ -168,7 +168,7 @@ export const image = { code: 0 }, protyle: editor.protyle, - action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML], + action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML, Constants.CB_GET_AV_NO_CREATE], }); event.preventDefault(); event.stopPropagation(); @@ -198,27 +198,30 @@ export const image = { const liElement = target.parentElement; confirmDialog(window.siyuan.languages.deleteOpConfirm, `${window.siyuan.languages.delete} ${liElement.querySelector(".b3-list-item__text").textContent}`, () => { if (liElement.getAttribute("data-tab-type") === "unRefAV") { + const id = liElement.getAttribute("data-item"); fetchPost("/api/av/removeUnusedAttributeView", { - id: liElement.getAttribute("data-item"), + id, }, () => { if (liElement.parentElement.querySelectorAll("li").length === 1) { liElement.parentElement.innerHTML = `
  • ${window.siyuan.languages.emptyContent}
  • `; } else { liElement.remove(); } - onGet({ - data: { + if (editor.protyle.element.querySelector(`.av[data-av-id="${id}"]`)) { + onGet({ data: { - content: "", - id: Lute.NewNodeID(), - rootID: Lute.NewNodeID(), + data: { + content: "", + id: Lute.NewNodeID(), + rootID: Lute.NewNodeID(), + }, + msg: "", + code: 0 }, - msg: "", - code: 0 - }, - protyle: editor.protyle, - action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML], - }); + protyle: editor.protyle, + action: [Constants.CB_GET_HISTORY, Constants.CB_GET_HTML], + }); + } }); } else { fetchPost("/api/asset/removeUnusedAsset", { @@ -281,7 +284,7 @@ export const image = { data.forEach((item) => { html += `
  • ${escapeHtml(item.name || item.item)} - + ${boxOpenHTML} diff --git a/app/src/constants.ts b/app/src/constants.ts index dd0734ac6..e4e95f76a 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -139,6 +139,7 @@ export abstract class Constants { public static readonly CB_GET_HTML = "cb-get-html"; // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位 public static readonly CB_GET_HISTORY = "cb-get-history"; // 历史渲染 public static readonly CB_GET_OPENNEW = "cb-get-opennew"; // 编辑器只读后新建文件需为临时解锁状态 & https://github.com/siyuan-note/siyuan/issues/12197 + public static readonly CB_GET_AV_NO_CREATE = "cb-get-av-no-create"; // 属性视图不自动创建 // localstorage public static readonly LOCAL_ZOOM = "local-zoom"; diff --git a/app/src/protyle/render/av/render.ts b/app/src/protyle/render/av/render.ts index 77156fd62..e13f657c2 100644 --- a/app/src/protyle/render/av/render.ts +++ b/app/src/protyle/render/av/render.ts @@ -569,6 +569,7 @@ export const avRender = async (element: Element, protyle: IProtyle, cb?: (data: viewID: e.getAttribute(Constants.CUSTOM_SY_AV_VIEW) || "", query: resetData.query.trim(), blockID: e.getAttribute("data-node-id"), + createIfNotExist: !protyle.block.action?.includes(Constants.CB_GET_AV_NO_CREATE), }); data = response.data; } else { diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index 411d3b8e2..c0974b41e 100644 --- a/app/src/types/protyle.d.ts +++ b/app/src/types/protyle.d.ts @@ -39,7 +39,8 @@ type TProtyleAction = "cb-get-append" | // 向下滚动加载 "cb-get-rootscroll" | // 如果为 rootID 就滚动到指定位置,必有 rootID "cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位 "cb-get-history" | // 历史渲染 - "cb-get-opennew" // 编辑器只读后新建文件需为临时解锁状态 & https://github.com/siyuan-note/siyuan/issues/12197 + "cb-get-opennew" | // 编辑器只读后新建文件需为临时解锁状态 & https://github.com/siyuan-note/siyuan/issues/12197 + "cb-get-av-no-create" // 属性视图不自动创建 /** @link https://ld246.com/article/1588412297062 */ interface ILuteRender {