From e6a84f9e1412300f8a6bacfd67c3b63788116a48 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 1 Dec 2023 11:29:44 +0800 Subject: [PATCH] :art: Supports multiple views for the database https://github.com/siyuan-note/siyuan/issues/9751 --- kernel/av/av.go | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/kernel/av/av.go b/kernel/av/av.go index 11cff4a09..8a475dce6 100644 --- a/kernel/av/av.go +++ b/kernel/av/av.go @@ -23,6 +23,7 @@ import ( "math" "os" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -747,27 +748,18 @@ func (av *AttributeView) GetBlockKey() (ret *Key) { return } -func (av *AttributeView) GetDuplicateViewName(masterViewName string) string { - count := 1 - ret := masterViewName + " (" + strconv.Itoa(count) + ")" - - existViewByName := func(name string) bool { - for _, v := range av.Views { - if v.Name == name { - return true - } - } - return false +func (av *AttributeView) GetDuplicateViewName(masterViewName string) (ret string) { + ret = masterViewName + " (1)" + r := regexp.MustCompile("^(.*) \\((\\d+)\\)$") + m := r.FindStringSubmatch(masterViewName) + if nil == m || 3 > len(m) { + return } - for i := 0; i < 32; i++ { - if !existViewByName(ret) { - return ret - } - count++ - ret = masterViewName + " (" + strconv.Itoa(count) + ")" - } - return ret + num, _ := strconv.Atoi(m[2]) + num++ + ret = fmt.Sprintf("%s (%d)", m[1], num) + return } func GetAttributeViewDataPath(avID string) (ret string) {