mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-07 16:04:19 +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
ea178b40f3
commit
a2a3bca000
4 changed files with 40 additions and 38 deletions
|
|
@ -18,6 +18,7 @@
|
|||
package av
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
|
@ -444,6 +445,40 @@ func GetAttributeViewNameByPath(avJSONPath string) (ret string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetAttributeViewContent(avID string) (content string) {
|
||||
if "" == avID {
|
||||
return
|
||||
}
|
||||
|
||||
attrView, err := ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
buf.WriteString(attrView.Name)
|
||||
buf.WriteByte(' ')
|
||||
for _, v := range attrView.Views {
|
||||
buf.WriteString(v.Name)
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
buf.WriteString(keyValues.Key.Name)
|
||||
buf.WriteByte(' ')
|
||||
for _, value := range keyValues.Values {
|
||||
if nil != value {
|
||||
buf.WriteString(value.String(true))
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
content = strings.TrimSpace(buf.String())
|
||||
return
|
||||
}
|
||||
|
||||
func IsAttributeViewExist(avID string) bool {
|
||||
avJSONPath := GetAttributeViewDataPath(avID)
|
||||
return filelock.IsExist(avJSONPath)
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ func buildSearchHistoryQueryFilter(query, op, box, table string, typ int) (stmt
|
|||
case HistoryTypeAsset:
|
||||
stmt += table + " MATCH '{title content}:(" + query + ")'"
|
||||
case HistoryTypeDatabase:
|
||||
stmt += table + " MATCH '{title}:(" + query + ")'"
|
||||
stmt += table + " MATCH '{content}:(" + query + ")'"
|
||||
}
|
||||
} else {
|
||||
stmt += "1=1"
|
||||
|
|
@ -987,12 +987,13 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
|
|||
}
|
||||
p := strings.TrimPrefix(database, util.HistoryDir)
|
||||
p = filepath.ToSlash(p[1:])
|
||||
avName, _ := av.GetAttributeViewNameByPath(database)
|
||||
content := av.GetAttributeViewContent(id)
|
||||
histories = append(histories, &sql.History{
|
||||
ID: id,
|
||||
Type: HistoryTypeDatabase,
|
||||
Op: op,
|
||||
Title: id + avName,
|
||||
Title: id,
|
||||
Content: content,
|
||||
Path: p,
|
||||
Created: created,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -741,40 +741,6 @@ func FillAttributeViewNilValue(value *av.Value, typ av.KeyType) {
|
|||
}
|
||||
}
|
||||
|
||||
func getAttributeViewContent(avID string) (content string) {
|
||||
if "" == avID {
|
||||
return
|
||||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return
|
||||
}
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
buf.WriteString(attrView.Name)
|
||||
buf.WriteByte(' ')
|
||||
for _, v := range attrView.Views {
|
||||
buf.WriteString(v.Name)
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
|
||||
for _, keyValues := range attrView.KeyValues {
|
||||
buf.WriteString(keyValues.Key.Name)
|
||||
buf.WriteByte(' ')
|
||||
for _, value := range keyValues.Values {
|
||||
if nil != value {
|
||||
buf.WriteString(value.String(true))
|
||||
buf.WriteByte(' ')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
content = strings.TrimSpace(buf.String())
|
||||
return
|
||||
}
|
||||
|
||||
func getBlockValue(keyValues []*av.KeyValues) (ret *av.Value) {
|
||||
for _, kv := range keyValues {
|
||||
if av.KeyTypeBlock == kv.Key.Type && 0 < len(kv.Values) {
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||
|
||||
if ast.NodeAttributeView == node.Type {
|
||||
if fullAttrView {
|
||||
return getAttributeViewContent(node.AttributeViewID)
|
||||
return av.GetAttributeViewContent(node.AttributeViewID)
|
||||
}
|
||||
|
||||
ret, _ := av.GetAttributeViewName(node.AttributeViewID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue