改进数据量较大时的启动速度 https://github.com/siyuan-note/siyuan/issues/6574

This commit is contained in:
Liang Ding 2022-11-14 11:05:42 +08:00
parent b3c9eba73a
commit cdf2b79678
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 39 additions and 8 deletions

View file

@ -17,6 +17,7 @@
package util
import (
"io"
"os"
"path"
"path/filepath"
@ -194,6 +195,27 @@ func SizeOfDirectory(path string) (size int64, err error) {
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 {
if 100*1024*1024 > size {
return 100 * 1024 * 1024

View file

@ -25,7 +25,6 @@ import (
"github.com/88250/gulu"
"github.com/denisbrodbeck/machineid"
"github.com/dustin/go-humanize"
"github.com/siyuan-note/logging"
)
@ -41,9 +40,6 @@ const (
)
func logBootInfo() {
s, _ := SizeOfDirectory(DataDir)
dataDirSize := humanize.Bytes(uint64(s))
logging.LogInfof("kernel is booting:\n"+
" * ver [%s]\n"+
" * arch [%s]\n"+
@ -53,8 +49,8 @@ func logBootInfo() {
" * read only [%v]\n"+
" * container [%s]\n"+
" * database [ver=%s]\n"+
" * workspace directory [%s, data %s]",
Ver, runtime.GOARCH, os.Getpid(), Mode, WorkingDir, ReadOnly, Container, DatabaseVer, WorkspaceDir, dataDirSize)
" * workspace directory [%s]",
Ver, runtime.GOARCH, os.Getpid(), Mode, WorkingDir, ReadOnly, Container, DatabaseVer, WorkspaceDir)
}
func IsMutexLocked(m *sync.Mutex) bool {