Bladeren bron

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

Vanessa 8 maanden geleden
bovenliggende
commit
a9e8642251
2 gewijzigde bestanden met toevoegingen van 13 en 3 verwijderingen
  1. 9 1
      app/src/search/util.ts
  2. 4 2
      app/src/util/fetch.ts

+ 9 - 1
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;
                 }

+ 4 - 2
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;
             }