Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/8512

Vanessa0c33bb16d99e
diff --git a/app/src/constants.ts b/app/src/constants.ts
index 20fb4af357..07659c5351 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -89,6 +89,7 @@ export abstract class Constants {
public static readonly TIMEOUT_INPUT = 256;
public static readonly TIMEOUT_LOAD = 300;
public static readonly TIMEOUT_TRANSITION = 300;
+ public static readonly TIMEOUT_COUNT = 1000;
// id
public static readonly HELP_PATH = {
diff --git a/app/src/layout/status.ts b/app/src/layout/status.ts
index c15837b4f9..0dd34ece9b 100644
--- a/app/src/layout/status.ts
+++ b/app/src/layout/status.ts
@@ -149,23 +149,27 @@ export const initStatus = (isWindow = false) => {
};
let countRootId: string;
+let countTimeout: number;
export const countSelectWord = (range: Range, rootID?: string) => {
/// #if !MOBILE
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
- const selectText = range.toString();
- if (selectText) {
- fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
- renderStatusbarCounter(response.data);
- });
- countRootId = "";
- } else if (rootID && rootID !== countRootId) {
- countRootId = rootID;
- fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
- renderStatusbarCounter(response.data);
- });
- }
+ clearTimeout(countTimeout);
+ countTimeout = window.setTimeout(() => {
+ const selectText = range.toString();
+ if (selectText) {
+ fetchPost("/api/block/getContentWordCount", {"content": range.toString()}, (response) => {
+ renderStatusbarCounter(response.data);
+ });
+ countRootId = "";
+ } else if (rootID && rootID !== countRootId) {
+ countRootId = rootID;
+ fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
+ renderStatusbarCounter(response.data);
+ });
+ }
+ }, Constants.TIMEOUT_COUNT);
/// #endif
};
@@ -174,26 +178,30 @@ export const countBlockWord = (ids: string[], rootID?: string, clearCache = fals
if (document.getElementById("status").classList.contains("fn__none")) {
return;
}
- if (clearCache) {
- countRootId = "";
- }
- if (ids.length > 0) {
- fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
- renderStatusbarCounter(response.data);
- });
- countRootId = "";
- } else if (rootID && rootID !== countRootId) {
- countRootId = rootID;
- fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
- renderStatusbarCounter(response.data);
- });
- }
+ clearTimeout(countTimeout);
+ countTimeout = window.setTimeout(() => {
+ if (clearCache) {
+ countRootId = "";
+ }
+ if (ids.length > 0) {
+ fetchPost("/api/block/getBlocksWordCount", {ids}, (response) => {
+ renderStatusbarCounter(response.data);
+ });
+ countRootId = "";
+ } else if (rootID && rootID !== countRootId) {
+ countRootId = rootID;
+ fetchPost("/api/block/getTreeStat", {id: rootID}, (response) => {
+ renderStatusbarCounter(response.data);
+ });
+ }
+ }, Constants.TIMEOUT_COUNT);
/// #endif
};
export const clearCounter = () => {
countRootId = "";
document.querySelector("#status .status__counter").innerHTML = "";
+ clearTimeout(countTimeout);
};
export const renderStatusbarCounter = (stat: {