Skip to content

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

:bug: Ignore deleted blocks in word count requests https://github.com/siyuan-note/siyuan/issues/19137

Danielb917ff8facdb
diff --git a/kernel/api/block.go b/kernel/api/block.go
index c40c352137..7d02f9ad8c 100644
--- a/kernel/api/block.go
+++ b/kernel/api/block.go
@@ -806,7 +806,7 @@ func getBlocksWordCount(c *gin.Context) {
ids = append(ids, id.(string))
}
boxID := encryptedNotebookFromArg(arg)
- if !holdBlockRequest(c, ret, boxID, arg) {
+ if !holdBlockRequest(c, ret, boxID, arg, true) {
return
}
ids = filterBlockIDsByPublishAccess(c, ids, boxID)
diff --git a/kernel/api/block_test.go b/kernel/api/block_test.go
index b15da8d7e9..ecaa32366e 100644
--- a/kernel/api/block_test.go
+++ b/kernel/api/block_test.go
@@ -361,6 +361,10 @@ func TestBlockPublishAccessGuards(t *testing.T) {
if response["code"].(float64) != 0 || response["data"].(map[string]any)[missingID] != false {
t.Fatalf("missing blocks should report false without an API error: %v", response)
}
+ response = blockGuardRequest(model.RoleAdministrator, `{"ids":["`+missingID+`"]}`, getBlocksWordCount)
+ if response["code"].(float64) != 0 || response["data"].(map[string]any)["stat"].(map[string]any)["blockCount"].(float64) != 0 {
+ t.Fatalf("missing blocks should be ignored by word count without an API error: %v", response)
+ }
})
}
diff --git a/kernel/filesys/stat.go b/kernel/filesys/stat.go
index b00064d80d..e3bb0623d9 100644
--- a/kernel/filesys/stat.go
+++ b/kernel/filesys/stat.go
@@ -267,7 +267,7 @@ func BlocksWordCount(ids []string) (ret *util.BlockStatResult) {
ret.LinkCount += linkCnt
ret.ImageCount += imgCnt
ret.RefCount += refCnt
+ ret.BlockCount++
}
- ret.BlockCount = len(ids)
return
}