🎨 Data History - File history - Assets support update operation indexing https://github.com/siyuan-note/siyuan/issues/11177

This commit is contained in:
Daniel 2024-04-28 21:38:28 +08:00
parent f2c593b807
commit dca46b9056
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017
2 changed files with 15 additions and 23 deletions

View File

@ -41,7 +41,10 @@ func GetAssets() (ret map[string]*Asset) {
assetsLock.Lock() assetsLock.Lock()
defer assetsLock.Unlock() defer assetsLock.Unlock()
ret = assetsCache ret = map[string]*Asset{}
for k, v := range assetsCache {
ret[k] = v
}
return return
} }

View File

@ -36,6 +36,7 @@ import (
"github.com/siyuan-note/eventbus" "github.com/siyuan-note/eventbus"
"github.com/siyuan-note/filelock" "github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging" "github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/conf" "github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/filesys" "github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search" "github.com/siyuan-note/siyuan/kernel/search"
@ -480,8 +481,8 @@ func GetNotebookHistory() (ret []*History, err error) {
} }
func generateAssetsHistory() { func generateAssetsHistory() {
files := recentModifiedAssets() assets := recentModifiedAssets()
if 1 > len(files) { if 1 > len(assets) {
return return
} }
@ -491,7 +492,7 @@ func generateAssetsHistory() {
return return
} }
for _, file := range files { for _, file := range assets {
historyPath := filepath.Join(historyDir, "assets", strings.TrimPrefix(file, filepath.Join(util.DataDir, "assets"))) historyPath := filepath.Join(historyDir, "assets", strings.TrimPrefix(file, filepath.Join(util.DataDir, "assets")))
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err { if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
logging.LogErrorf("generate history failed: %s", err) logging.LogErrorf("generate history failed: %s", err)
@ -626,28 +627,16 @@ func (box *Box) recentModifiedDocs() (ret []string) {
return return
} }
var ( var assetsLatestHistoryTime = time.Now().Unix()
assetsUpdated = map[string]int64{}
)
func recentModifiedAssets() (ret []string) { func recentModifiedAssets() (ret []string) {
filelock.Walk(filepath.Join(util.DataDir, "assets"), func(path string, info fs.FileInfo, err error) error { assets := cache.GetAssets()
if nil == info { for _, asset := range assets {
return nil if asset.Updated > assetsLatestHistoryTime {
ret = append(ret, filepath.Join(util.DataDir, asset.Path))
} }
}
if info.IsDir() { assetsLatestHistoryTime = time.Now().Unix()
return nil
}
updated := info.ModTime().Unix()
oldUpdated, ok := assetsUpdated[path]
if ok && updated > oldUpdated {
ret = append(ret, path)
}
assetsUpdated[path] = updated
return nil
})
return return
} }