mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
⚡ 改进数据量较大时的启动速度 https://github.com/siyuan-note/siyuan/issues/6574
This commit is contained in:
parent
b3c9eba73a
commit
cdf2b79678
4 changed files with 39 additions and 8 deletions
|
|
@ -23,6 +23,8 @@ type Stat struct {
|
||||||
CBlockCount int `json:"cBlockCount"`
|
CBlockCount int `json:"cBlockCount"`
|
||||||
DataSize int64 `json:"dataSize"`
|
DataSize int64 `json:"dataSize"`
|
||||||
CDataSize int64 `json:"cDataSize"`
|
CDataSize int64 `json:"cDataSize"`
|
||||||
|
AssetsSize int64 `json:"assetsSize"`
|
||||||
|
CAssetsSize int64 `json:"cAssetsSize"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStat() *Stat {
|
func NewStat() *Stat {
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,13 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"github.com/88250/lute/ast"
|
||||||
"github.com/88250/lute/parse"
|
"github.com/88250/lute/parse"
|
||||||
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/facette/natsort"
|
"github.com/facette/natsort"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
|
|
@ -52,20 +54,29 @@ type Box struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func AutoStat() {
|
func AutoStat() {
|
||||||
|
time.Sleep(time.Minute)
|
||||||
autoStat()
|
autoStat()
|
||||||
for range time.Tick(10 * time.Minute) {
|
for range time.Tick(2 * time.Hour) {
|
||||||
autoStat()
|
autoStat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var statLock = sync.Mutex{}
|
||||||
|
|
||||||
func autoStat() {
|
func autoStat() {
|
||||||
|
statLock.Lock()
|
||||||
|
defer statLock.Unlock()
|
||||||
|
|
||||||
Conf.Stat.TreeCount = treenode.CountTrees()
|
Conf.Stat.TreeCount = treenode.CountTrees()
|
||||||
Conf.Stat.CTreeCount = treenode.CeilCount(Conf.Stat.TreeCount)
|
Conf.Stat.CTreeCount = treenode.CeilCount(Conf.Stat.TreeCount)
|
||||||
Conf.Stat.BlockCount = treenode.CountBlocks()
|
Conf.Stat.BlockCount = treenode.CountBlocks()
|
||||||
Conf.Stat.CBlockCount = treenode.CeilCount(Conf.Stat.BlockCount)
|
Conf.Stat.CBlockCount = treenode.CeilCount(Conf.Stat.BlockCount)
|
||||||
Conf.Stat.DataSize, _ = util.SizeOfDirectory(util.DataDir)
|
Conf.Stat.DataSize, Conf.Stat.AssetsSize = util.DataSize()
|
||||||
Conf.Stat.CDataSize = util.CeilSize(Conf.Stat.DataSize)
|
Conf.Stat.CDataSize = util.CeilSize(Conf.Stat.DataSize)
|
||||||
|
Conf.Stat.CAssetsSize = util.CeilSize(Conf.Stat.AssetsSize)
|
||||||
Conf.Save()
|
Conf.Save()
|
||||||
|
|
||||||
|
logging.LogInfof("auto stat [trees=%d, blocks=%d, dataSize=%s, assetsSize=%s]", Conf.Stat.TreeCount, Conf.Stat.BlockCount, humanize.Bytes(uint64(Conf.Stat.DataSize)), humanize.Bytes(uint64(Conf.Stat.AssetsSize)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func ListNotebooks() (ret []*Box, err error) {
|
func ListNotebooks() (ret []*Box, err error) {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -194,6 +195,27 @@ func SizeOfDirectory(path string) (size int64, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DataSize() (dataSize, assetsSize int64) {
|
||||||
|
filepath.Walk(DataDir, func(path string, info os.FileInfo, err error) error {
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("size of data failed: %s", err)
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
s := info.Size()
|
||||||
|
dataSize += s
|
||||||
|
|
||||||
|
if strings.Contains(strings.TrimPrefix(path, DataDir), "assets") {
|
||||||
|
assetsSize += s
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dataSize += 4096
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func CeilSize(size int64) int64 {
|
func CeilSize(size int64) int64 {
|
||||||
if 100*1024*1024 > size {
|
if 100*1024*1024 > size {
|
||||||
return 100 * 1024 * 1024
|
return 100 * 1024 * 1024
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import (
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/denisbrodbeck/machineid"
|
"github.com/denisbrodbeck/machineid"
|
||||||
"github.com/dustin/go-humanize"
|
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -41,9 +40,6 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func logBootInfo() {
|
func logBootInfo() {
|
||||||
s, _ := SizeOfDirectory(DataDir)
|
|
||||||
dataDirSize := humanize.Bytes(uint64(s))
|
|
||||||
|
|
||||||
logging.LogInfof("kernel is booting:\n"+
|
logging.LogInfof("kernel is booting:\n"+
|
||||||
" * ver [%s]\n"+
|
" * ver [%s]\n"+
|
||||||
" * arch [%s]\n"+
|
" * arch [%s]\n"+
|
||||||
|
|
@ -53,8 +49,8 @@ func logBootInfo() {
|
||||||
" * read only [%v]\n"+
|
" * read only [%v]\n"+
|
||||||
" * container [%s]\n"+
|
" * container [%s]\n"+
|
||||||
" * database [ver=%s]\n"+
|
" * database [ver=%s]\n"+
|
||||||
" * workspace directory [%s, data %s]",
|
" * workspace directory [%s]",
|
||||||
Ver, runtime.GOARCH, os.Getpid(), Mode, WorkingDir, ReadOnly, Container, DatabaseVer, WorkspaceDir, dataDirSize)
|
Ver, runtime.GOARCH, os.Getpid(), Mode, WorkingDir, ReadOnly, Container, DatabaseVer, WorkspaceDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsMutexLocked(m *sync.Mutex) bool {
|
func IsMutexLocked(m *sync.Mutex) bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue