Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve cleaning up unreferenced databases https://github.com/siyuan-note/siyuan/issues/11569#issuecomment-3884008188 (#17089)

Jeffrey Chen39c3cea7635c
diff --git a/app/src/config/image.ts b/app/src/config/image.ts
index be2f9f6625..8da9e862f4 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} <b>${liElement.querySelector(".b3-list-item__text").textContent}</b>`, () => {
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 = `<li class="b3-list--empty">${window.siyuan.languages.emptyContent}</li>`;
} 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 += `<li data-tab-type="${type}" data-item="${item.item}" class="b3-list-item${isM ? "" : " b3-list-item--hide-action"}">
<span class="b3-list-item__text">${escapeHtml(item.name || item.item)}</span>
- <span data-type="copy" class="ariaLabel b3-list-item__action" aria-label="${window.siyuan.languages[type === "unRefAV" ? "copyMirror" : "copy"]}">
+ <span data-type="copy" class="ariaLabel b3-list-item__action" aria-label="${type === "unRefAV" ? window.siyuan.languages.copyMirror : window.siyuan.languages.copy}">
<svg><use xlink:href="#iconCopy"></use></svg>
</span>
${boxOpenHTML}
diff --git a/app/src/constants.ts b/app/src/constants.ts
index dd0734ac6e..e4e95f76a1 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 77156fd626..e13f657c28 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 411d3b8e24..c0974b41e6 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 {