Skip to content

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

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

Daniel6e85d12d5e75
diff --git a/kernel/av/av.go b/kernel/av/av.go
index db83f7ed83..c2424eb6c2 100644
--- a/kernel/av/av.go
+++ b/kernel/av/av.go
@@ -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)
diff --git a/kernel/model/history.go b/kernel/model/history.go
index c8868fddce..152a0da00d 100644
--- a/kernel/model/history.go
+++ b/kernel/model/history.go
@@ -987,7 +987,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
}
p := strings.TrimPrefix(database, util.HistoryDir)
p = filepath.ToSlash(p[1:])
- content := av.GetAttributeViewContent(id)
+ content := av.GetAttributeViewContentByPath(database)
histories = append(histories, &sql.History{
ID: id,
Type: HistoryTypeDatabase,