From 03c2611c0f5418daa09645b2a4cb6249419eae2e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sun, 22 Dec 2024 17:38:30 +0800 Subject: [PATCH 1/3] :art: Improve boot sync --- kernel/model/repository.go | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 8ecb35c0b..6edde3830 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -1288,14 +1288,13 @@ func bootSyncRepo() (err error) { isBootSyncing.Store(true) - start := time.Now() - waitGroup := sync.WaitGroup{} var errs []error waitGroup.Add(1) go func() { defer waitGroup.Done() + start := time.Now() _, _, indexErr := indexRepoBeforeCloudSync(repo) if indexErr != nil { errs = append(errs, indexErr) @@ -1311,6 +1310,8 @@ func bootSyncRepo() (err error) { isBootSyncing.Store(false) return } + + logging.LogInfof("boot index repo elapsed [%.2fs]", time.Since(start).Seconds()) }() var fetchedFiles []*entity.File @@ -1318,6 +1319,7 @@ func bootSyncRepo() (err error) { go func() { defer waitGroup.Done() + start := time.Now() syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar} cloudLatest, getErr := repo.GetCloudLatest(syncContext) if nil != getErr { @@ -1342,29 +1344,14 @@ func bootSyncRepo() (err error) { isBootSyncing.Store(false) return } + + logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", time.Since(start).Seconds()) }() waitGroup.Wait() if 0 < len(errs) { err = errs[0] - return } - syncingFiles = sync.Map{} - syncingStorages.Store(false) - for _, fetchedFile := range fetchedFiles { - name := path.Base(fetchedFile.Path) - if strings.HasSuffix(name, ".sy") { - id := name[:len(name)-3] - syncingFiles.Store(id, true) - continue - } - if strings.HasPrefix(fetchedFile.Path, "/storage/") { - syncingStorages.Store(true) - } - } - - elapsed := time.Since(start) - logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", elapsed.Seconds()) if err != nil { autoSyncErrCount++ planSyncAfter(fixSyncInterval) @@ -1387,6 +1374,20 @@ func bootSyncRepo() (err error) { return } + syncingFiles = sync.Map{} + syncingStorages.Store(false) + for _, fetchedFile := range fetchedFiles { + name := path.Base(fetchedFile.Path) + if strings.HasSuffix(name, ".sy") { + id := name[:len(name)-3] + syncingFiles.Store(id, true) + continue + } + if strings.HasPrefix(fetchedFile.Path, "/storage/") { + syncingStorages.Store(true) + } + } + if 0 < len(fetchedFiles) { go func() { _, syncErr := syncRepo(false, false) From b195629d1a65e2504dac98081c477b433b3c4880 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 23 Dec 2024 11:20:31 +0800 Subject: [PATCH 2/3] :zap: Reduce startup time when sync is enabled https://github.com/siyuan-note/siyuan/issues/13589 --- kernel/go.mod | 2 +- kernel/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index 1c7682868..996d73f38 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -56,7 +56,7 @@ require ( github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 github.com/sashabaranov/go-openai v1.29.1 github.com/shirou/gopsutil/v3 v3.24.5 - github.com/siyuan-note/dejavu v0.0.0-20241220041421-b6410d912871 + github.com/siyuan-note/dejavu v0.0.0-20241223030943-e7887b6676f2 github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4 github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 github.com/siyuan-note/filelock v0.0.0-20241212013445-c66518cdacfa diff --git a/kernel/go.sum b/kernel/go.sum index 841582627..d955c1f11 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -365,8 +365,8 @@ github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+D github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+tqMccdGMwuEU+hjux/zL6xSmf5S9ITaA= github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw= github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8= -github.com/siyuan-note/dejavu v0.0.0-20241220041421-b6410d912871 h1:U65kVBfF0+PYdlJ1btDxhIfuUElmz7iRbtu3yyyIo8w= -github.com/siyuan-note/dejavu v0.0.0-20241220041421-b6410d912871/go.mod h1:YtT05UDgrYO5Cb/aWc2COwqId56n6qHP+jptvITAags= +github.com/siyuan-note/dejavu v0.0.0-20241223030943-e7887b6676f2 h1:UG2aeo6ME5B/EZ6h0pGjQrqyx89yOHUdE+aUIdDEqZk= +github.com/siyuan-note/dejavu v0.0.0-20241223030943-e7887b6676f2/go.mod h1:+gaHpNFsoVagw956l456Cm4eZclB/gXsjkW4YmvWmJM= github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4 h1:kJaw5L/evyW6LcB9IQT8PR4ppx8JVqOFP9Ix3rfwSrc= github.com/siyuan-note/encryption v0.0.0-20231219001248-1e028a4d13b4/go.mod h1:UYcCCY+0wh+GmUoDOaO63j1sV5lgy7laLAk1XhEiUis= github.com/siyuan-note/eventbus v0.0.0-20240627125516-396fdb0f0f97 h1:lM5v8BfNtbOL5jYwhCdMYBcYtr06IYBKjjSLAPMKTM8= From 25f934ecb4c3959cd833d03e51d289d2fbfe936c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Mon, 23 Dec 2024 16:14:16 +0800 Subject: [PATCH 3/3] :art: Improve exporting HTML/Word --- kernel/model/export.go | 6 ++---- kernel/model/session.go | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel/model/export.go b/kernel/model/export.go index 1b2dbffba..c0f963ae0 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -711,13 +711,12 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string } } - srcs := []string{"stage/build/export", "stage/build/fonts", "stage/protyle"} + srcs := []string{"stage/build/export", "stage/protyle"} for _, src := range srcs { from := filepath.Join(util.WorkingDir, src) to := filepath.Join(savePath, src) if err := filelock.Copy(from, to); err != nil { logging.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err) - return } } @@ -869,7 +868,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do } if !pdf && "" != savePath { // 导出 HTML 需要复制静态资源 - srcs := []string{"stage/build/export", "stage/build/fonts", "stage/protyle"} + srcs := []string{"stage/build/export", "stage/protyle"} for _, src := range srcs { from := filepath.Join(util.WorkingDir, src) to := filepath.Join(savePath, src) @@ -899,7 +898,6 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do to := filepath.Join(savePath, "appearance", src) if err := filelock.Copy(from, to); err != nil { logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err) - return } } diff --git a/kernel/model/session.go b/kernel/model/session.go index 46a8c1f7e..3d8b7314f 100644 --- a/kernel/model/session.go +++ b/kernel/model/session.go @@ -214,7 +214,6 @@ func CheckAuth(c *gin.Context) { // 放过 /appearance/ if strings.HasPrefix(c.Request.RequestURI, "/appearance/") || strings.HasPrefix(c.Request.RequestURI, "/stage/build/export/") || - strings.HasPrefix(c.Request.RequestURI, "/stage/build/fonts/") || strings.HasPrefix(c.Request.RequestURI, "/stage/protyle/") { c.Next() return