🎨 Supports cleaning up unreferenced databases https://github.com/siyuan-note/siyuan/issues/11569

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2026-01-29 10:28:48 +08:00
parent efe11801ad
commit 9a610cae0a
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 19 additions and 30 deletions

View file

@ -97,7 +97,7 @@ func RemoveUnusedAttributeViews() (ret []string) {
}
for _, unusedAv := range unusedAttributeViews {
id := unusedAv["id"].(string)
id := unusedAv.Item
srcPath := filepath.Join(util.DataDir, "storage", "av", id+".json")
if filelock.IsExist(srcPath) {
historyPath := filepath.Join(historyDir, "storage", "av", id+".json")
@ -108,7 +108,7 @@ func RemoveUnusedAttributeViews() (ret []string) {
}
for _, unusedAv := range unusedAttributeViews {
id := unusedAv["id"].(string)
id := unusedAv.Item
absPath := filepath.Join(util.DataDir, "storage", "av", id+".json")
if filelock.IsExist(absPath) {
info, statErr := os.Stat(absPath)
@ -132,9 +132,9 @@ func RemoveUnusedAttributeViews() (ret []string) {
return
}
func UnusedAttributeViews() (ret []map[string]any) {
func UnusedAttributeViews() (ret []*UnusedItem) {
defer logging.Recover()
ret = []map[string]any{}
ret = []*UnusedItem{}
allAvIDs, err := getAllAvIDs()
if err != nil {
@ -172,16 +172,9 @@ func UnusedAttributeViews() (ret []map[string]any) {
for _, id := range allAvIDs {
if !docReferencedAvIDs[id] && !isRelatedSrcAvDocReferenced(id, docReferencedAvIDs, checkedAvIDs) {
name, _ := av.GetAttributeViewName(id)
ret = append(ret, map[string]any{
"item": id,
"name": name,
})
ret = append(ret, &UnusedItem{Item: id, Name: name})
}
}
if 1 > len(ret) {
ret = []map[string]any{}
}
return
}