Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:zap: Improve performance of importing .sy.zip https://github.com/siyuan-note/siyuan/issues/10874

Danield9370560e5c7
diff --git a/kernel/model/import.go b/kernel/model/import.go
index 48a91e1042..641e0cea14 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -149,16 +149,18 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
// 新 ID 保留时间部分,仅修改随机值,避免时间变化导致更新时间早于创建时间
// Keep original creation time when importing .sy.zip https://github.com/siyuan-note/siyuan/issues/9923
- newNodeID := util.TimeFromID(n.ID) + "-" + gulu.Rand.String(7)
+ newNodeID := util.TimeFromID(n.ID) + "-" + util.RandString(7)
blockIDs[n.ID] = newNodeID
oldNodeID := n.ID
n.ID = newNodeID
n.SetIALAttr("id", newNodeID)
// 重新指向数据库属性值
- ial := parse.IAL2Map(n.KramdownIAL)
- for k, _ := range ial {
- if strings.HasPrefix(k, av.NodeAttrNameAvs) {
+ for _, kv := range n.KramdownIAL {
+ if 2 > len(kv) {
+ continue
+ }
+ if strings.HasPrefix(kv[0], av.NodeAttrNameAvs) {
avBlockIDs[oldNodeID] = newNodeID
}
}
diff --git a/kernel/util/misc.go b/kernel/util/misc.go
index 6ef47299f2..c339917cf1 100644
--- a/kernel/util/misc.go
+++ b/kernel/util/misc.go
@@ -18,13 +18,31 @@ package util
import (
"bytes"
+ "math/rand"
"strconv"
"strings"
+ "time"
"unicode"
"github.com/88250/lute/html"
)
+func init() {
+ rand.Seed(time.Now().UTC().UnixNano())
+}
+
+var (
+ letter = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
+)
+
+func RandString(length int) string {
+ b := make([]rune, length)
+ for i := range b {
+ b[i] = letter[rand.Intn(len(letter))]
+ }
+ return string(b)
+}
+
// InsertElem inserts value at index into a.
// 0 <= index <= len(s)
func InsertElem[T any](s []T, index int, value T) []T {