mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 数据统计
This commit is contained in:
parent
70490f3e16
commit
953ce38ab7
7 changed files with 51 additions and 12 deletions
8
app/src/types/index.d.ts
vendored
8
app/src/types/index.d.ts
vendored
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
|
|
||||||
|
|
@ -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, ".")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue