mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-13 07:56:14 +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
a2a3bca000
commit
6e85d12d5e
2 changed files with 19 additions and 1 deletions
|
|
@ -455,7 +455,19 @@ func GetAttributeViewContent(avID string) (content string) {
|
||||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||||
return
|
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 := bytes.Buffer{}
|
||||||
buf.WriteString(attrView.Name)
|
buf.WriteString(attrView.Name)
|
||||||
buf.WriteByte(' ')
|
buf.WriteByte(' ')
|
||||||
|
|
@ -486,11 +498,17 @@ func IsAttributeViewExist(avID string) bool {
|
||||||
|
|
||||||
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
func ParseAttributeView(avID string) (ret *AttributeView, err error) {
|
||||||
avJSONPath := GetAttributeViewDataPath(avID)
|
avJSONPath := GetAttributeViewDataPath(avID)
|
||||||
|
return ParseAttributeViewByPath(avJSONPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseAttributeViewByPath(avJSONPath string) (ret *AttributeView, err error) {
|
||||||
if !filelock.IsExist(avJSONPath) {
|
if !filelock.IsExist(avJSONPath) {
|
||||||
err = ErrViewNotFound
|
err = ErrViewNotFound
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avID := filepath.Base(avJSONPath)
|
||||||
|
avID = strings.TrimSuffix(avID, filepath.Ext(avID))
|
||||||
data, readErr := filelock.ReadFile(avJSONPath)
|
data, readErr := filelock.ReadFile(avJSONPath)
|
||||||
if nil != readErr {
|
if nil != readErr {
|
||||||
logging.LogErrorf("read attribute view [%s] failed: %s", avID, readErr)
|
logging.LogErrorf("read attribute view [%s] failed: %s", avID, readErr)
|
||||||
|
|
|
||||||
|
|
@ -987,7 +987,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
||||||
}
|
}
|
||||||
p := strings.TrimPrefix(database, util.HistoryDir)
|
p := strings.TrimPrefix(database, util.HistoryDir)
|
||||||
p = filepath.ToSlash(p[1:])
|
p = filepath.ToSlash(p[1:])
|
||||||
content := av.GetAttributeViewContent(id)
|
content := av.GetAttributeViewContentByPath(database)
|
||||||
histories = append(histories, &sql.History{
|
histories = append(histories, &sql.History{
|
||||||
ID: id,
|
ID: id,
|
||||||
Type: HistoryTypeDatabase,
|
Type: HistoryTypeDatabase,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue