mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Improve database rollup field filtering https://github.com/siyuan-note/siyuan/issues/15740
This commit is contained in:
parent
7b2e48d54e
commit
04c46b3a56
5 changed files with 69 additions and 57 deletions
|
|
@ -1465,16 +1465,16 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
|
|||
return
|
||||
}
|
||||
|
||||
attrViewCache := map[string]*av.AttributeView{}
|
||||
cachedAttrViews := map[string]*av.AttributeView{}
|
||||
avIDs := strings.Split(avs, ",")
|
||||
for _, avID := range avIDs {
|
||||
attrView := attrViewCache[avID]
|
||||
attrView := cachedAttrViews[avID]
|
||||
if nil == attrView {
|
||||
attrView, _ = av.ParseAttributeView(avID)
|
||||
if nil == attrView {
|
||||
return
|
||||
}
|
||||
attrViewCache[avID] = attrView
|
||||
cachedAttrViews[avID] = attrView
|
||||
}
|
||||
|
||||
if !attrView.ExistBoundBlock(nodeID) {
|
||||
|
|
@ -1572,42 +1572,7 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
|
|||
|
||||
// 再渲染关联和汇总
|
||||
|
||||
rollupFurtherCollections := map[string]av.Collection{}
|
||||
for _, kv := range keyValues {
|
||||
if av.KeyTypeRollup != kv.Key.Type {
|
||||
continue
|
||||
}
|
||||
|
||||
relKey, _ := attrView.GetKey(kv.Key.Rollup.RelationKeyID)
|
||||
if nil == relKey {
|
||||
continue
|
||||
}
|
||||
|
||||
destAv := attrViewCache[relKey.Relation.AvID]
|
||||
if nil == destAv {
|
||||
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
||||
if nil == destAv {
|
||||
continue
|
||||
}
|
||||
attrViewCache[relKey.Relation.AvID] = destAv
|
||||
}
|
||||
|
||||
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
|
||||
if nil == destKey {
|
||||
continue
|
||||
}
|
||||
isSameAv := destAv.ID == attrView.ID
|
||||
|
||||
var furtherCollection av.Collection
|
||||
if av.KeyTypeTemplate == destKey.Type || (!isSameAv && (av.KeyTypeUpdated == destKey.Type || av.KeyTypeCreated == destKey.Type)) {
|
||||
viewable := sql.RenderView(destAv, destAv.Views[0], "")
|
||||
if nil != viewable {
|
||||
furtherCollection = viewable.(av.Collection)
|
||||
}
|
||||
}
|
||||
rollupFurtherCollections[kv.Key.ID] = furtherCollection
|
||||
}
|
||||
|
||||
rollupFurtherCollections := sql.GetFurtherCollections(attrView, cachedAttrViews)
|
||||
for _, kv := range keyValues {
|
||||
switch kv.Key.Type {
|
||||
case av.KeyTypeRollup:
|
||||
|
|
@ -1622,13 +1587,13 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
|
|||
|
||||
relVal := attrView.GetValue(kv.Key.Rollup.RelationKeyID, kv.Values[0].BlockID)
|
||||
if nil != relVal && nil != relVal.Relation {
|
||||
destAv := attrViewCache[relKey.Relation.AvID]
|
||||
destAv := cachedAttrViews[relKey.Relation.AvID]
|
||||
if nil == destAv {
|
||||
destAv, _ = av.ParseAttributeView(relKey.Relation.AvID)
|
||||
if nil == destAv {
|
||||
break
|
||||
}
|
||||
attrViewCache[relKey.Relation.AvID] = destAv
|
||||
cachedAttrViews[relKey.Relation.AvID] = destAv
|
||||
}
|
||||
|
||||
destKey, _ := destAv.GetKey(kv.Key.Rollup.KeyID)
|
||||
|
|
@ -1642,14 +1607,14 @@ func GetBlockAttributeViewKeys(nodeID string) (ret []*BlockAttributeViewKeys) {
|
|||
break
|
||||
}
|
||||
|
||||
destAv := attrViewCache[kv.Key.Relation.AvID]
|
||||
destAv := cachedAttrViews[kv.Key.Relation.AvID]
|
||||
if nil == destAv {
|
||||
destAv, _ = av.ParseAttributeView(kv.Key.Relation.AvID)
|
||||
if nil == destAv {
|
||||
break
|
||||
}
|
||||
|
||||
attrViewCache[kv.Key.Relation.AvID] = destAv
|
||||
cachedAttrViews[kv.Key.Relation.AvID] = destAv
|
||||
}
|
||||
|
||||
blocks := map[string]*av.Value{}
|
||||
|
|
@ -2070,8 +2035,10 @@ func GetCurrentAttributeViewImages(avID, viewID, query string) (ret []string, er
|
|||
view = attrView.GetView(attrView.ViewID)
|
||||
}
|
||||
|
||||
cachedAttrViews := map[string]*av.AttributeView{}
|
||||
rollupFurtherCollections := sql.GetFurtherCollections(attrView, cachedAttrViews)
|
||||
table := getAttrViewTable(attrView, view, query)
|
||||
av.Filter(table, attrView)
|
||||
av.Filter(table, attrView, rollupFurtherCollections, cachedAttrViews)
|
||||
av.Sort(table, attrView)
|
||||
|
||||
ids := map[string]bool{}
|
||||
|
|
@ -3284,8 +3251,10 @@ func getNewValueByNearItem(nearItem av.Item, key *av.Key, addingBlockID string)
|
|||
}
|
||||
|
||||
func getNearItem(attrView *av.AttributeView, view, groupView *av.View, previousItemID string) (ret av.Item) {
|
||||
cachedAttrViews := map[string]*av.AttributeView{}
|
||||
rollupFurtherCollections := sql.GetFurtherCollections(attrView, cachedAttrViews)
|
||||
viewable := sql.RenderGroupView(attrView, view, groupView, "")
|
||||
av.Filter(viewable, attrView)
|
||||
av.Filter(viewable, attrView, rollupFurtherCollections, cachedAttrViews)
|
||||
av.Sort(viewable, attrView)
|
||||
items := viewable.(av.Collection).GetItems()
|
||||
if 0 < len(items) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue