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

Daniel9a610cae0aad
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index 8824ce3839..77de9640b7 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -738,7 +738,7 @@ func RemoveUnusedAssets() (ret []string) {
var hashes []string
for _, unusedAsset := range unusedAssets {
- p := unusedAsset["item"].(string)
+ p := unusedAsset.Item
historyPath := filepath.Join(historyDir, p)
if p = filepath.Join(util.DataDir, p); filelock.IsExist(p) {
if filelock.IsHidden(p) {
@@ -758,7 +758,7 @@ func RemoveUnusedAssets() (ret []string) {
sql.BatchRemoveAssetsQueue(hashes)
for _, unusedAsset := range unusedAssets {
- p := unusedAsset["item"].(string)
+ p := unusedAsset.Item
absPath := filepath.Join(util.DataDir, p)
if filelock.IsExist(absPath) {
info, statErr := os.Stat(absPath)
@@ -967,9 +967,14 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
return
}
-func UnusedAssets() (ret []map[string]any) {
+type UnusedItem struct {
+ Item string `json:"item"`
+ Name string `json:"name"`
+}
+
+func UnusedAssets() (ret []*UnusedItem) {
defer logging.Recover()
- ret = []map[string]any{}
+ ret = []*UnusedItem{}
assetsPathMap, err := allAssetAbsPaths()
if err != nil {
@@ -1124,17 +1129,14 @@ func UnusedAssets() (ret []map[string]any) {
p = p[1:]
}
name := util.RemoveID(path.Base(p))
- ret = append(ret, map[string]any{
- "item": p,
- "name": name,
- })
+ ret = append(ret, &UnusedItem{Item: p, Name: name})
}
return
}
-func MissingAssets() (ret []map[string]any) {
+func MissingAssets() (ret []*UnusedItem) {
defer logging.Recover()
- ret = []map[string]any{}
+ ret = []*UnusedItem{}
assetsPathMap, err := allAssetAbsPaths()
if err != nil {
@@ -1203,17 +1205,11 @@ func MissingAssets() (ret []map[string]any) {
// Assets starting with `.` should not be considered missing assets https://github.com/siyuan-note/siyuan/issues/8821
if !filelock.IsExist(filepath.Join(util.DataDir, dest)) {
name := util.RemoveID(path.Base(dest))
- ret = append(ret, map[string]any{
- "item": dest,
- "name": name,
- })
+ ret = append(ret, &UnusedItem{Item: dest, Name: name})
}
} else {
name := util.RemoveID(path.Base(dest))
- ret = append(ret, map[string]any{
- "item": dest,
- "name": name,
- })
+ ret = append(ret, &UnusedItem{Item: dest, Name: name})
}
continue
}
diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go
index 252ce0811a..b1751a2d16 100644
--- a/kernel/model/attribute_view.go
+++ b/kernel/model/attribute_view.go
@@ -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
}