Skip to content

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

:bug: 搜索为空和非空切换时结果被覆盖

Vanessaa9e864225111
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 4631b95d7c..e03e5354d4 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -1320,9 +1320,9 @@ export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchCo
if (rmCurrentCriteria) {
element.querySelector("#criteria .b3-chip--current")?.classList.remove("b3-chip--current");
}
- const searchInputElement = element.querySelector("#searchInput") as HTMLInputElement;
const loadingElement = element.querySelector(".fn__loading--top");
loadingElement.classList.remove("fn__none");
+ const searchInputElement = element.querySelector("#searchInput") as HTMLInputElement;
const inputValue = searchInputElement.value;
element.querySelector("#searchList").scrollTo(0, 0);
const previousElement = element.querySelector('[data-type="previous"]');
@@ -1337,6 +1337,10 @@ export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchCo
const searchResultElement = element.querySelector("#searchResult");
if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
+ if (window.siyuan.reqIds["/api/block/getRecentUpdatedBlocks"] && window.siyuan.reqIds["/api/search/fullTextSearchBlock"] &&
+ window.siyuan.reqIds["/api/block/getRecentUpdatedBlocks"] < window.siyuan.reqIds["/api/search/fullTextSearchBlock"]) {
+ return;
+ }
onSearch(response.data, edit, element, config);
loadingElement.classList.add("fn__none");
searchResultElement.innerHTML = "";
@@ -1358,6 +1362,10 @@ export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchCo
orderBy: config.sort,
page: config.page || 1,
}, (response) => {
+ if (window.siyuan.reqIds["/api/block/getRecentUpdatedBlocks"] && window.siyuan.reqIds["/api/search/fullTextSearchBlock"] &&
+ window.siyuan.reqIds["/api/block/getRecentUpdatedBlocks"] > window.siyuan.reqIds["/api/search/fullTextSearchBlock"]) {
+ return;
+ }
if (!config.page) {
config.page = 1;
}
diff --git a/app/src/util/fetch.ts b/app/src/util/fetch.ts
index 9a41edc324..40bfe63dc9 100644
--- a/app/src/util/fetch.ts
+++ b/app/src/util/fetch.ts
@@ -10,7 +10,8 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
method: "POST",
};
if (data) {
- if (["/api/search/searchRefBlock", "/api/graph/getGraph", "/api/graph/getLocalGraph"].includes(url)) {
+ if (["/api/search/searchRefBlock", "/api/graph/getGraph", "/api/graph/getLocalGraph",
+ "/api/block/getRecentUpdatedBlocks", "/api/search/fullTextSearchBlock"].includes(url)) {
window.siyuan.reqIds[url] = new Date().getTime();
if (data.type === "local" && url === "/api/graph/getLocalGraph") {
// 当打开文档A的关系图、关系图、文档A后刷新,由于防止请求重复处理,文档A关系图无法渲染。
@@ -54,7 +55,8 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
}
return;
}
- if (["/api/search/searchRefBlock", "/api/graph/getGraph", "/api/graph/getLocalGraph"].includes(url)) {
+ if (["/api/search/searchRefBlock", "/api/graph/getGraph", "/api/graph/getLocalGraph",
+ "/api/block/getRecentUpdatedBlocks", "/api/search/fullTextSearchBlock"].includes(url)) {
if (response.data.reqId && window.siyuan.reqIds[url] && window.siyuan.reqIds[url] > response.data.reqId) {
return;
}