From 7a83808d45b41a4a6c9160988b95a4bb2901995b Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 25 Jun 2022 19:54:57 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E4=BA=91=E7=AB=AF=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=95=B0=E6=8D=AE=E4=BB=93=E5=BA=93=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/5142?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/go.mod | 2 +- kernel/go.sum | 4 +- kernel/model/repository.go | 79 +++++++++++++++++++++++--------------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index cc18857bb..f78c37244 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -40,7 +40,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/qiniu/go-sdk/v7 v7.13.0 github.com/radovskyb/watcher v1.0.7 - github.com/siyuan-note/dejavu v0.0.0-20220625090001-05561417a463 + github.com/siyuan-note/dejavu v0.0.0-20220625094848-7e1437e9c8c2 github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f github.com/siyuan-note/filelock v0.0.0-20220616063212-74cfba0754ee diff --git a/kernel/go.sum b/kernel/go.sum index 6ea506667..1d08e668e 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -421,8 +421,8 @@ github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/siyuan-note/dejavu v0.0.0-20220625090001-05561417a463 h1:2SIMu/hVkMuuVGXPMCmkWHWklPZ0I/6KnIAOOvD9cnM= -github.com/siyuan-note/dejavu v0.0.0-20220625090001-05561417a463/go.mod h1:i7dnOgHM41EA7xIX2CYSxYe0WhksGZidQQsLvWryK7w= +github.com/siyuan-note/dejavu v0.0.0-20220625094848-7e1437e9c8c2 h1:G0gSYBcywwHgHQesFo/tGbKc2tEGsWBmncEuGpGH1Xg= +github.com/siyuan-note/dejavu v0.0.0-20220625094848-7e1437e9c8c2/go.mod h1:i7dnOgHM41EA7xIX2CYSxYe0WhksGZidQQsLvWryK7w= github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676 h1:QB9TjJQFhXhZ6dAtPpY02DlzHAQm1C+WqZq6OadG8mI= github.com/siyuan-note/encryption v0.0.0-20220612074546-f1dd94fe8676/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20220624162334-ca7c06dc771f h1:JMobMNZ7AqaKKyEK+WeWFhix/2TDQXgPZDajU00IybU= diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 5bfa3f7e9..1bcb293d5 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -26,7 +26,6 @@ import ( "github.com/88250/gulu" "github.com/siyuan-note/dejavu" - "github.com/siyuan-note/dejavu/entity" "github.com/siyuan-note/encryption" "github.com/siyuan-note/eventbus" "github.com/siyuan-note/filelock" @@ -35,20 +34,60 @@ import ( ) func init() { + eventbus.Subscribe(dejavu.EvtIndexWalkData, func(path string) { + msg := "Indexing repo walk data [" + path + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) + }) + eventbus.Subscribe(dejavu.EvtIndexGetLatestFile, func(path string) { + msg := "Indexing repo get latest file [" + path + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) + }) + eventbus.Subscribe(dejavu.EvtIndexUpsertFile, func(path string) { + msg := "Indexing repo upsert file [" + path + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) + }) + + eventbus.Subscribe(dejavu.EvtCheckoutWalkData, func(path string) { + msg := "Checkout repo walk data [" + path + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) + }) + eventbus.Subscribe(dejavu.EvtCheckoutUpsertFile, func(path string) { + msg := "Checkout repo upsert file [" + path + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) + }) + eventbus.Subscribe(dejavu.EvtCheckoutRemoveFile, func(path string) { + msg := "Checkout repo remove file [" + path + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) + }) + eventbus.Subscribe(dejavu.EvtSyncBeforeDownloadCloudIndexes, func(latestSync string) { - util.SetBootDetails("Downloading repo indexes...") + msg := "Downloading repo indexes..." + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) }) eventbus.Subscribe(dejavu.EvtSyncBeforeDownloadCloudFile, func(id string) { - util.SetBootDetails("Downloading repo object [" + id + "]") + msg := "Downloading repo object [" + id + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) }) eventbus.Subscribe(dejavu.EvtSyncBeforeDownloadCloudChunk, func(id string) { - util.SetBootDetails("Downloading repo object [" + id + "]") + msg := "Downloading repo object [" + id + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) }) eventbus.Subscribe(dejavu.EvtSyncBeforeUploadObject, func(id string) { - util.SetBootDetails("Uploading repo object [" + id + "]") + msg := "Uploading repo object [" + id + "]" + util.SetBootDetails(msg) + util.PushEndlessProgress(msg) }) } @@ -164,18 +203,6 @@ func InitRepoKey() (err error) { return } -var checkoutCallbacks = map[string]dejavu.Callback{ - "walkData": func(context, arg interface{}, err error) { - context.(func(msg string))(arg.(string)) - }, - "upsertFile": func(context, arg interface{}, err error) { - context.(func(msg string))(arg.(*entity.File).Path) - }, - "removeFile": func(context, arg interface{}, err error) { - context.(func(msg string))(arg.(string)) - }, -} - func CheckoutRepo(id string) (err error) { if 1 > len(Conf.Repo.Key) { err = errors.New(Conf.Language(26)) @@ -202,7 +229,7 @@ func CheckoutRepo(id string) (err error) { Conf.Sync.Enabled = false Conf.Save() - err = repo.Checkout(id, util.PushEndlessProgress, checkoutCallbacks) + err = repo.Checkout(id) if nil != err { util.PushClearProgress() return @@ -218,18 +245,6 @@ func CheckoutRepo(id string) (err error) { return } -var indexCallbacks = map[string]dejavu.Callback{ - "walkData": func(context, arg interface{}, err error) { - context.(func(msg string))(arg.(string)) - }, - "getLatestFile": func(context, arg interface{}, err error) { - context.(func(msg string))(arg.(*entity.File).Path) - }, - "upsertFile": func(context, arg interface{}, err error) { - context.(func(msg string))(arg.(*entity.File).Path) - }, -} - func IndexRepo(memo string) (err error) { if 1 > len(Conf.Repo.Key) { err = errors.New(Conf.Language(26)) @@ -254,7 +269,7 @@ func IndexRepo(memo string) (err error) { WaitForWritingFiles() sql.WaitForWritingDatabase() filelock.ReleaseAllFileLocks() - _, err = repo.Index(memo, util.PushEndlessProgress, indexCallbacks) + _, err = repo.Index(memo) util.PushClearProgress() return } @@ -272,7 +287,7 @@ func indexRepoBeforeCloudSync() { start := time.Now() latest, err := repo.Latest() - index, err := repo.Index("[Auto] Cloud sync", nil, nil) + index, err := repo.Index("[Auto] Cloud sync") if nil != err { util.LogErrorf("index repo before cloud sync failed: %s", err) return