🎨 数据统计

This commit is contained in:
Liang Ding 2022-11-10 18:45:41 +08:00
parent 70490f3e16
commit 953ce38ab7
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 51 additions and 12 deletions

View file

@ -405,6 +405,14 @@ declare interface IConfig {
virtualRefAlias: boolean virtualRefAlias: boolean
virtualRefAnchor: boolean virtualRefAnchor: boolean
virtualRefDoc: boolean virtualRefDoc: boolean
},
stat: {
treeCount: number
cTreeCount: number
blockCount: number
cBlockCount: number
dataSize: number
cDataSize: number
} }
} }

View file

@ -142,6 +142,9 @@ export const addGA = () => {
subscriptionType: -1, subscriptionType: -1,
syncEnabled: false, syncEnabled: false,
syncProvider: -1, syncProvider: -1,
cTreeCount: window.siyuan.config.stat.cTreeCount,
cBlockCount: window.siyuan.config.stat.cBlockCount,
cDataSize: window.siyuan.config.stat.cDataSize,
}; };
if (window.siyuan.user) { if (window.siyuan.user) {
para.isLoggedIn = true; para.isLoggedIn = true;

View file

@ -17,11 +17,14 @@
package conf package conf
type Stat struct { type 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 { func NewStat() *Stat {
return &Stat{ return &Stat{}
DocCount: 0,
}
} }

View file

@ -52,13 +52,19 @@ type Box struct {
} }
func AutoStat() { func AutoStat() {
autoStat()
for range time.Tick(10 * time.Minute) { for range time.Tick(10 * time.Minute) {
autoStat() autoStat()
} }
} }
func 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() Conf.Save()
} }

View file

@ -92,10 +92,3 @@ func getStat(key string) (ret string) {
row.Scan(&ret) row.Scan(&ret)
return return
} }
func CountAllDoc() (ret int) {
sqlStmt := "SELECT COUNT(*) FROM blocks WHERE type = 'd'"
row := queryRow(sqlStmt)
row.Scan(&ret)
return
}

View file

@ -71,6 +71,19 @@ func CountBlocks() (ret int) {
return len(blockTrees) 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 { func GetBlockTreeRootByPath(boxID, path string) *BlockTree {
blockTreesLock.Lock() blockTreesLock.Lock()
defer blockTreesLock.Unlock() defer blockTreesLock.Unlock()

View file

@ -209,6 +209,19 @@ func SizeOfDirectory(path string) (size int64, err error) {
return 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 { func IsReservedFilename(baseName string) bool {
return "assets" == baseName || "templates" == baseName || "widgets" == baseName || "emojis" == baseName || ".siyuan" == baseName || strings.HasPrefix(baseName, ".") return "assets" == baseName || "templates" == baseName || "widgets" == baseName || "emojis" == baseName || ".siyuan" == baseName || strings.HasPrefix(baseName, ".")
} }