🎨 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-30 00:12:29 +08:00
parent a2a3bca000
commit 6e85d12d5e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 19 additions and 1 deletions

View file

@ -455,7 +455,19 @@ func GetAttributeViewContent(avID string) (content string) {
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
return
}
return getAttributeViewContent0(attrView)
}
func GetAttributeViewContentByPath(avJSONPath string) (content string) {
attrView, err := ParseAttributeViewByPath(avJSONPath)
if err != nil {
logging.LogErrorf("parse attribute view [%s] failed: %s", avJSONPath, err)
return
}
return getAttributeViewContent0(attrView)
}
func getAttributeViewContent0(attrView *AttributeView) (content string) {
buf := bytes.Buffer{}
buf.WriteString(attrView.Name)
buf.WriteByte(' ')
@ -486,11 +498,17 @@ func IsAttributeViewExist(avID string) bool {
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
avJSONPath := GetAttributeViewDataPath(avID)
return ParseAttributeViewByPath(avJSONPath)
}
func ParseAttributeViewByPath(avJSONPath string) (ret *AttributeView, err error) {
if !filelock.IsExist(avJSONPath) {
err = ErrViewNotFound
return
}
avID := filepath.Base(avJSONPath)
avID = strings.TrimSuffix(avID, filepath.Ext(avID))
data, readErr := filelock.ReadFile(avJSONPath)
if nil != readErr {
logging.LogErrorf("read attribute view [%s] failed: %s", avID, readErr)