mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-08 00:04:21 +01:00
⚡ Improve data indexing to reduce disk read operations https://github.com/siyuan-note/siyuan/issues/16958
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
dc00060062
commit
87282404bb
4 changed files with 65 additions and 45 deletions
|
|
@ -21,9 +21,11 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -69,16 +71,7 @@ func docTitleImgAsset(root *ast.Node, boxLocalPath, docDirLocalPath string) *Ass
|
|||
return nil
|
||||
}
|
||||
|
||||
var hash string
|
||||
var err error
|
||||
if lp := assetLocalPath(p, boxLocalPath, docDirLocalPath); "" != lp {
|
||||
hash, err = util.GetEtag(lp)
|
||||
if err != nil {
|
||||
logging.LogErrorf("calc asset [%s] hash failed: %s", lp, err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
hash := assetHashByLocalPath(p, boxLocalPath, docDirLocalPath)
|
||||
name, _ := util.LastID(p)
|
||||
asset := &Asset{
|
||||
ID: ast.NewNodeID(),
|
||||
|
|
@ -126,6 +119,22 @@ func scanAssetRows(rows *sql.Rows) (ret *Asset) {
|
|||
return
|
||||
}
|
||||
|
||||
func assetHashByLocalPath(linkDest, boxLocalPath, docDirLocalPath string) (ret string) {
|
||||
if lp := assetLocalPath(linkDest, boxLocalPath, docDirLocalPath); "" != lp {
|
||||
if !gulu.File.IsDir(lp) {
|
||||
if assetHash := cache.GetAssetHashByPath(linkDest); nil != assetHash {
|
||||
ret = assetHash.Hash
|
||||
} else {
|
||||
ret, _ = util.GetEtag(lp)
|
||||
if "" != ret {
|
||||
cache.SetAssetHash(ret, linkDest)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func assetLocalPath(linkDest, boxLocalPath, docDirLocalPath string) (ret string) {
|
||||
ret = filepath.Join(docDirLocalPath, linkDest)
|
||||
if filelock.IsExist(ret) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue