mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-08 00:04:21 +01:00
🎨 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:
parent
efe11801ad
commit
9a610cae0a
2 changed files with 19 additions and 30 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue