From d679bedd773ed556149d227440113300321dc983 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 12 Dec 2022 22:22:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=88=97?= =?UTF-8?q?=E5=87=BA=E5=92=8C=E5=88=87=E6=8D=A2=E6=9C=80=E8=BF=91=E6=89=93?= =?UTF-8?q?=E5=BC=80=E7=9A=84=E6=96=87=E6=A1=A3=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3293?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/storage.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/kernel/model/storage.go b/kernel/model/storage.go index cf6252bae..0851989e4 100644 --- a/kernel/model/storage.go +++ b/kernel/model/storage.go @@ -17,14 +17,15 @@ package model import ( - "github.com/88250/lute/parse" "os" "path/filepath" "sync" "github.com/88250/gulu" + "github.com/88250/lute/parse" "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" + "github.com/siyuan-note/siyuan/kernel/treenode" "github.com/siyuan-note/siyuan/kernel/util" ) @@ -127,7 +128,7 @@ func setRecentDocs(recentDocs []*RecentDoc) (err error) { } func getRecentDocs() (ret []*RecentDoc, err error) { - ret = []*RecentDoc{} + tmp := []*RecentDoc{} dataPath := filepath.Join(util.DataDir, "storage/recent-doc.json") if !gulu.File.IsExist(dataPath) { return @@ -139,10 +140,22 @@ func getRecentDocs() (ret []*RecentDoc, err error) { return } - if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err { + if err = gulu.JSON.UnmarshalJSON(data, &tmp); nil != err { logging.LogErrorf("unmarshal storage [recent-doc] failed: %s", err) return } + + var notExists []string + for _, doc := range tmp { + if nil != treenode.GetBlockTree(doc.RootID) { + ret = append(ret, doc) + } else { + notExists = append(notExists, doc.RootID) + } + } + if 0 < len(notExists) { + setRecentDocs(ret) + } return } From 3b1b62fb7ef27c6299ce3ca978a933a80d0a0bf7 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 12 Dec 2022 22:27:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:art:=20=E6=94=AF=E6=8C=81=E5=88=97?= =?UTF-8?q?=E5=87=BA=E5=92=8C=E5=88=87=E6=8D=A2=E6=9C=80=E8=BF=91=E6=89=93?= =?UTF-8?q?=E5=BC=80=E7=9A=84=E6=96=87=E6=A1=A3=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3293?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/storage.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/kernel/model/storage.go b/kernel/model/storage.go index 0851989e4..813bb72dc 100644 --- a/kernel/model/storage.go +++ b/kernel/model/storage.go @@ -80,17 +80,14 @@ func SetRecentDoc(doc *RecentDoc) (err error) { return } - update := false for i, c := range recentDocs { if c.RootID == doc.RootID { - recentDocs[i] = doc - update = true + recentDocs = append(recentDocs[:i], recentDocs[i+1:]...) break } } - if !update { - recentDocs = append([]*RecentDoc{doc}, recentDocs...) - } + + recentDocs = append([]*RecentDoc{doc}, recentDocs...) if 32 < len(recentDocs) { recentDocs = recentDocs[:32] }