An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 数据统计
Liang Ding953ce38ab75d
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 83faf18543..3f8a42a3dd 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -405,6 +405,14 @@ declare interface IConfig {virtualRefAlias: booleanvirtualRefAnchor: booleanvirtualRefDoc: boolean+ },+ stat: {+ treeCount: number+ cTreeCount: number+ blockCount: number+ cBlockCount: number+ dataSize: number+ cDataSize: number}}diff --git a/app/src/util/assets.ts b/app/src/util/assets.tsindex eaff334244..b8163aae2e 100644--- a/app/src/util/assets.ts+++ b/app/src/util/assets.ts@@ -142,6 +142,9 @@ export const addGA = () => {subscriptionType: -1,syncEnabled: false,syncProvider: -1,+ cTreeCount: window.siyuan.config.stat.cTreeCount,+ cBlockCount: window.siyuan.config.stat.cBlockCount,+ cDataSize: window.siyuan.config.stat.cDataSize,};if (window.siyuan.user) {para.isLoggedIn = true;diff --git a/kernel/conf/stat.go b/kernel/conf/stat.goindex 56a3ab094e..55778ab5c0 100644--- a/kernel/conf/stat.go+++ b/kernel/conf/stat.go@@ -17,11 +17,14 @@package conftype Stat struct {- DocCount int `json:"docCount"` // 总文档计数+ TreeCount int `json:"treeCount"`+ CTreeCount int `json:"cTreeCount"`+ BlockCount int `json:"blockCount"`+ CBlockCount int `json:"cBlockCount"`+ DataSize int64 `json:"dataSize"`+ CDataSize int64 `json:"cDataSize"`}func NewStat() *Stat {- return &Stat{- DocCount: 0,- }+ return &Stat{}}diff --git a/kernel/model/box.go b/kernel/model/box.goindex 6e5e0854a7..324e043e06 100644--- a/kernel/model/box.go+++ b/kernel/model/box.go@@ -52,13 +52,19 @@ type Box struct {}func AutoStat() {+ autoStat()for range time.Tick(10 * time.Minute) {autoStat()}}func autoStat() {- Conf.Stat.DocCount = sql.CountAllDoc()+ Conf.Stat.TreeCount = treenode.CountTrees()+ Conf.Stat.CTreeCount = treenode.CeilCount(Conf.Stat.TreeCount)+ Conf.Stat.BlockCount = treenode.CountBlocks()+ Conf.Stat.BlockCount = treenode.CeilCount(Conf.Stat.BlockCount)+ Conf.Stat.DataSize, _ = util.SizeOfDirectory(util.DataDir)+ Conf.Stat.CDataSize = util.CeilSize(Conf.Stat.DataSize)Conf.Save()}diff --git a/kernel/sql/stat.go b/kernel/sql/stat.goindex 8e0f2f45e6..e8222d8d5d 100644--- a/kernel/sql/stat.go+++ b/kernel/sql/stat.go@@ -92,10 +92,3 @@ func getStat(key string) (ret string) {row.Scan(&ret)return}--func CountAllDoc() (ret int) {- sqlStmt := "SELECT COUNT(*) FROM blocks WHERE type = 'd'"- row := queryRow(sqlStmt)- row.Scan(&ret)- return-}diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.goindex 173823dd9f..b79754cb3e 100644--- a/kernel/treenode/blocktree.go+++ b/kernel/treenode/blocktree.go@@ -71,6 +71,19 @@ func CountBlocks() (ret int) {return len(blockTrees)}+func CeilCount(count int) int {+ if 100 > count {+ return 100+ }++ for i := 1; i < 40; i++ {+ if count < i*500 {+ return i * 500+ }+ }+ return 500*40 + 1+}+func GetBlockTreeRootByPath(boxID, path string) *BlockTree {blockTreesLock.Lock()defer blockTreesLock.Unlock()diff --git a/kernel/util/file.go b/kernel/util/file.goindex 174db57d0c..526f91de8a 100644--- a/kernel/util/file.go+++ b/kernel/util/file.go@@ -209,6 +209,19 @@ func SizeOfDirectory(path string) (size int64, err error) {return}+func CeilSize(size int64) int64 {+ if 100*1024*1024 > size {+ return 100 * 1024 * 1024+ }++ for i := int64(1); i < 40; i++ {+ if 1024*1024*200*i > size {+ return 1024 * 1024 * int64(i)+ }+ }+ return 1024*1024*200*40 + 1+}+func IsReservedFilename(baseName string) bool {return "assets" == baseName || "templates" == baseName || "widgets" == baseName || "emojis" == baseName || ".siyuan" == baseName || strings.HasPrefix(baseName, ".")}