Browse Source

Merge remote-tracking branch 'origin/dev' into dev

Vanessa 6 months ago
parent
commit
3ea7daa308

+ 2 - 0
app/changelogs/v3.1.16/v3.1.16.md

@@ -24,6 +24,8 @@ Below are the detailed changes in this version.
 * [Add SQL query template function `querySQL`](https://github.com/siyuan-note/siyuan/issues/13455)
 * [Add SQL query template function `querySQL`](https://github.com/siyuan-note/siyuan/issues/13455)
 * [Search preview area supports inline memo positioning](https://github.com/siyuan-note/siyuan/issues/13465)
 * [Search preview area supports inline memo positioning](https://github.com/siyuan-note/siyuan/issues/13465)
 * [Add Arabic support](https://github.com/siyuan-note/siyuan/pull/13475)
 * [Add Arabic support](https://github.com/siyuan-note/siyuan/pull/13475)
+* [Improve exporting data](https://github.com/siyuan-note/siyuan/issues/13500)
+* [Improve serving assets performance](https://github.com/siyuan-note/siyuan/issues/13501)
 
 
 ### Bugfix
 ### Bugfix
 
 

+ 2 - 0
app/changelogs/v3.1.16/v3.1.16_zh_CHT.md

@@ -24,6 +24,8 @@
 * [新增 SQL 查詢範本函數 `querySQL`](https://github.com/siyuan-note/siyuan/issues/13455)
 * [新增 SQL 查詢範本函數 `querySQL`](https://github.com/siyuan-note/siyuan/issues/13455)
 * [搜尋預覽區域支援行級備註定位](https://github.com/siyuan-note/siyuan/issues/13465)
 * [搜尋預覽區域支援行級備註定位](https://github.com/siyuan-note/siyuan/issues/13465)
 * [新增阿拉伯語支援](https://github.com/siyuan-note/siyuan/pull/13475)
 * [新增阿拉伯語支援](https://github.com/siyuan-note/siyuan/pull/13475)
+* [改進匯出資料](https://github.com/siyuan-note/siyuan/issues/13500)
+* [改進資源檔案載入效能](https://github.com/siyuan-note/siyuan/issues/13501)
 
 
 ### 修復缺陷
 ### 修復缺陷
 
 

+ 2 - 0
app/changelogs/v3.1.16/v3.1.16_zh_CN.md

@@ -24,6 +24,8 @@
 * [添加 SQL 查询模板函数 `querySQL`](https://github.com/siyuan-note/siyuan/issues/13455)
 * [添加 SQL 查询模板函数 `querySQL`](https://github.com/siyuan-note/siyuan/issues/13455)
 * [搜索预览区域支持行级备注定位](https://github.com/siyuan-note/siyuan/issues/13465)
 * [搜索预览区域支持行级备注定位](https://github.com/siyuan-note/siyuan/issues/13465)
 * [添加阿拉伯语支持](https://github.com/siyuan-note/siyuan/pull/13475)
 * [添加阿拉伯语支持](https://github.com/siyuan-note/siyuan/pull/13475)
+* [改进导出数据](https://github.com/siyuan-note/siyuan/issues/13500)
+* [改进资源文件加载性能](https://github.com/siyuan-note/siyuan/issues/13501)
 
 
 ### 修复缺陷
 ### 修复缺陷
 
 

+ 1 - 1
app/src/assets/template/app/index.tpl

@@ -38,7 +38,7 @@
         if (refreshElement) {
         if (refreshElement) {
             refreshElement.style.display = ""
             refreshElement.style.display = ""
         }
         }
-    }, 2000)
+    }, 7000)
 </script>
 </script>
 </body>
 </body>
 </html>
 </html>

File diff suppressed because it is too large
+ 0 - 0
app/stage/protyle/js/lute/lute.min.js


+ 1 - 1
kernel/go.mod

@@ -10,7 +10,7 @@ require (
 	github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
 	github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
 	github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
 	github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
 	github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec
 	github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec
-	github.com/88250/lute v1.7.7-0.20241213121436-8647e479e280
+	github.com/88250/lute v1.7.7-0.20241216140552-8ec551250ce3
 	github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
 	github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
 	github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
 	github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4
 	github.com/ConradIrwin/font v0.0.0-20240627033111-8567075b2bfe
 	github.com/ConradIrwin/font v0.0.0-20240627033111-8567075b2bfe

+ 2 - 2
kernel/go.sum

@@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
 github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
 github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec h1:YsUSpByWJP+x8C+IT+C3QlFvU7ZQ6+E95SFd9+zy6QU=
 github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec h1:YsUSpByWJP+x8C+IT+C3QlFvU7ZQ6+E95SFd9+zy6QU=
 github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec/go.mod h1:c8uVw25vW2W4dhJ/j4iYsX5H1hc19spim266jO5x2hU=
 github.com/88250/gulu v1.2.3-0.20241212012748-c4dc08fe45ec/go.mod h1:c8uVw25vW2W4dhJ/j4iYsX5H1hc19spim266jO5x2hU=
-github.com/88250/lute v1.7.7-0.20241213121436-8647e479e280 h1:Ub4MpkyCTOvf3L1po5FUSJ1h52qlrThN8YQtbxbUu2s=
-github.com/88250/lute v1.7.7-0.20241213121436-8647e479e280/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
+github.com/88250/lute v1.7.7-0.20241216140552-8ec551250ce3 h1:5f7we6cT8uIaU6pPO3gU916JUxSodJEKwnykhhZFs50=
+github.com/88250/lute v1.7.7-0.20241216140552-8ec551250ce3/go.mod h1:WYyUw//5yVw9BJnoVjx7rI/3szsISxNZCYGOqTIrV0o=
 github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01 h1:AcFe63RXjIh1XtX/dc4Es3U8bYKjlEkvavHd1nFBOHM=
 github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01 h1:AcFe63RXjIh1XtX/dc4Es3U8bYKjlEkvavHd1nFBOHM=
 github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI=
 github.com/88250/pdfcpu v0.3.14-0.20241201033812-5a93b7586a01/go.mod h1:fVfOloBzs2+W2VJCCbq60XIxc3yJHAZ0Gahv1oO0gyI=
 github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=
 github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

+ 13 - 12
kernel/model/assets.go

@@ -322,13 +322,24 @@ func GetAssetAbsPath(relativePath string) (ret string, err error) {
 	if strings.Contains(relativePath, "?") {
 	if strings.Contains(relativePath, "?") {
 		relativePath = relativePath[:strings.Index(relativePath, "?")]
 		relativePath = relativePath[:strings.Index(relativePath, "?")]
 	}
 	}
+
+	// 在全局 assets 路径下搜索
+	p := filepath.Join(util.DataDir, relativePath)
+	if gulu.File.IsExist(p) {
+		ret = p
+		if !util.IsSubPath(util.WorkspaceDir, ret) {
+			err = fmt.Errorf("[%s] is not sub path of workspace", ret)
+			return
+		}
+		return
+	}
+
+	// 在笔记本下搜索
 	notebooks, err := ListNotebooks()
 	notebooks, err := ListNotebooks()
 	if err != nil {
 	if err != nil {
 		err = errors.New(Conf.Language(0))
 		err = errors.New(Conf.Language(0))
 		return
 		return
 	}
 	}
-
-	// 在笔记本下搜索
 	for _, notebook := range notebooks {
 	for _, notebook := range notebooks {
 		notebookAbsPath := filepath.Join(util.DataDir, notebook.ID)
 		notebookAbsPath := filepath.Join(util.DataDir, notebook.ID)
 		filelock.Walk(notebookAbsPath, func(path string, d fs.DirEntry, err error) error {
 		filelock.Walk(notebookAbsPath, func(path string, d fs.DirEntry, err error) error {
@@ -356,16 +367,6 @@ func GetAssetAbsPath(relativePath string) (ret string, err error) {
 		}
 		}
 	}
 	}
 
 
-	// 在全局 assets 路径下搜索
-	p := filepath.Join(util.DataDir, relativePath)
-	if gulu.File.IsExist(p) {
-		ret = p
-		if !util.IsSubPath(util.WorkspaceDir, ret) {
-			err = fmt.Errorf("[%s] is not sub path of workspace", ret)
-			return
-		}
-		return
-	}
 	return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
 	return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
 }
 }
 
 

+ 32 - 14
kernel/model/export.go

@@ -18,6 +18,7 @@ package model
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"crypto/sha1"
 	"encoding/csv"
 	"encoding/csv"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
@@ -1706,6 +1707,11 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
 	}
 	}
 
 
 	// 导出引用的资源文件
 	// 导出引用的资源文件
+	assetPathMap, err := allAssetAbsPaths()
+	if nil != err {
+		logging.LogWarnf("get assets abs path failed: %s", err)
+		return
+	}
 	copiedAssets := hashset.New()
 	copiedAssets := hashset.New()
 	for _, tree := range trees {
 	for _, tree := range trees {
 		var assets []string
 		var assets []string
@@ -1729,14 +1735,14 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
 				continue
 				continue
 			}
 			}
 
 
-			srcPath, assetErr := GetAssetAbsPath(asset)
-			if nil != assetErr {
-				logging.LogWarnf("get asset [%s] abs path failed: %s", asset, assetErr)
+			srcPath := assetPathMap[asset]
+			if "" == srcPath {
+				logging.LogWarnf("get asset [%s] abs path failed", asset)
 				continue
 				continue
 			}
 			}
 
 
 			destPath := filepath.Join(exportFolder, asset)
 			destPath := filepath.Join(exportFolder, asset)
-			assetErr = filelock.Copy(srcPath, destPath)
+			assetErr := filelock.Copy(srcPath, destPath)
 			if nil != assetErr {
 			if nil != assetErr {
 				logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
 				logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
 				continue
 				continue
@@ -1794,9 +1800,9 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
 							}
 							}
 
 
 							destPath := filepath.Join(exportFolder, asset.Content)
 							destPath := filepath.Join(exportFolder, asset.Content)
-							srcPath, assetErr := GetAssetAbsPath(asset.Content)
-							if nil != assetErr {
-								logging.LogWarnf("get asset [%s] abs path failed: %s", asset.Content, assetErr)
+							srcPath := assetPathMap[asset.Content]
+							if "" == srcPath {
+								logging.LogWarnf("get asset [%s] abs path failed", asset.Content)
 								continue
 								continue
 							}
 							}
 
 
@@ -3086,6 +3092,8 @@ func processFileAnnotationRef(refID string, n *ast.Node, fileAnnotationRefMode i
 
 
 func exportPandocConvertZip(baseFolderName string, docPaths []string,
 func exportPandocConvertZip(baseFolderName string, docPaths []string,
 	pandocFrom, pandocTo, ext string) (zipPath string) {
 	pandocFrom, pandocTo, ext string) (zipPath string) {
+	defer util.ClearPushProgress(100)
+
 	dir, name := path.Split(baseFolderName)
 	dir, name := path.Split(baseFolderName)
 	name = util.FilterFileName(name)
 	name = util.FilterFileName(name)
 	if strings.HasSuffix(name, "..") {
 	if strings.HasSuffix(name, "..") {
@@ -3146,8 +3154,15 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
 		docPaths = gulu.Str.RemoveDuplicatedElem(docPaths)
 		docPaths = gulu.Str.RemoveDuplicatedElem(docPaths)
 	}
 	}
 
 
+	wrotePathHash := map[string]string{}
+	assetsPathMap, err := allAssetAbsPaths()
+	if nil != err {
+		logging.LogWarnf("get assets abs path failed: %s", err)
+		return
+	}
+
 	luteEngine := util.NewLute()
 	luteEngine := util.NewLute()
-	for _, p := range docPaths {
+	for i, p := range docPaths {
 		id := util.GetTreeID(p)
 		id := util.GetTreeID(p)
 		hPath, md := exportMarkdownContent(id, exportRefMode, defBlockIDs)
 		hPath, md := exportMarkdownContent(id, exportRefMode, defBlockIDs)
 		dir, name = path.Split(hPath)
 		dir, name = path.Split(hPath)
@@ -3156,7 +3171,8 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
 		hPath = path.Join(dir, name)
 		hPath = path.Join(dir, name)
 		p = hPath + ext
 		p = hPath + ext
 		writePath := filepath.Join(exportFolder, p)
 		writePath := filepath.Join(exportFolder, p)
-		if gulu.File.IsExist(writePath) {
+		hash := fmt.Sprintf("%x", sha1.Sum([]byte(md)))
+		if gulu.File.IsExist(writePath) && hash != wrotePathHash[writePath] {
 			// 重名文档加 ID
 			// 重名文档加 ID
 			p = hPath + "-" + id + ext
 			p = hPath + "-" + id + ext
 			writePath = filepath.Join(exportFolder, p)
 			writePath = filepath.Join(exportFolder, p)
@@ -3181,15 +3197,14 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
 				continue
 				continue
 			}
 			}
 
 
-			srcPath, err := GetAssetAbsPath(asset)
-			if err != nil {
-				logging.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
+			srcPath := assetsPathMap[asset]
+			if "" == srcPath {
+				logging.LogWarnf("get asset [%s] abs path failed", asset)
 				continue
 				continue
 			}
 			}
 
 
 			destPath := filepath.Join(writeFolder, asset)
 			destPath := filepath.Join(writeFolder, asset)
-			err = filelock.Copy(srcPath, destPath)
-			if err != nil {
+			if copyErr := filelock.Copy(srcPath, destPath); copyErr != nil {
 				logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
 				logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
 				continue
 				continue
 			}
 			}
@@ -3201,6 +3216,9 @@ func exportPandocConvertZip(baseFolderName string, docPaths []string,
 			logging.LogErrorf("pandoc failed: %s", err)
 			logging.LogErrorf("pandoc failed: %s", err)
 			continue
 			continue
 		}
 		}
+
+		wrotePathHash[writePath] = hash
+		util.PushEndlessProgress(Conf.language(65) + " " + fmt.Sprintf(Conf.language(70), fmt.Sprintf("%d/%d %s", i+1, len(docPaths), name)))
 	}
 	}
 
 
 	zipPath = exportFolder + ".zip"
 	zipPath = exportFolder + ".zip"

+ 3 - 3
kernel/model/search.go

@@ -592,7 +592,7 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
 						return ast.WalkContinue
 						return ast.WalkContinue
 					}
 					}
 
 
-					replaceNodeTokens(n, method, keyword, replacement, r)
+					replaceNodeTokens(n, method, keyword, strings.TrimSpace(replacement), r)
 				case ast.NodeLinkText:
 				case ast.NodeLinkText:
 					if !replaceTypes["imgText"] {
 					if !replaceTypes["imgText"] {
 						return ast.WalkContinue
 						return ast.WalkContinue
@@ -673,11 +673,11 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
 						if replaceTypes["aHref"] {
 						if replaceTypes["aHref"] {
 							if 0 == method {
 							if 0 == method {
 								if strings.Contains(n.TextMarkAHref, keyword) {
 								if strings.Contains(n.TextMarkAHref, keyword) {
-									n.TextMarkAHref = strings.ReplaceAll(n.TextMarkAHref, keyword, replacement)
+									n.TextMarkAHref = strings.ReplaceAll(n.TextMarkAHref, keyword, strings.TrimSpace(replacement))
 								}
 								}
 							} else if 3 == method {
 							} else if 3 == method {
 								if nil != r && r.MatchString(n.TextMarkAHref) {
 								if nil != r && r.MatchString(n.TextMarkAHref) {
-									n.TextMarkAHref = r.ReplaceAllString(n.TextMarkAHref, replacement)
+									n.TextMarkAHref = r.ReplaceAllString(n.TextMarkAHref, strings.TrimSpace(replacement))
 								}
 								}
 							}
 							}
 						}
 						}

Some files were not shown because too many files changed in this diff