diff --git a/kernel/av/av.go b/kernel/av/av.go index db83f7ed8..c2424eb6c 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 c8868fddc..152a0da00 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,