1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

fix hasDepIds to look on RelationLinks instead of Relations

This commit is contained in:
Roman Khafizianov 2022-10-18 12:01:57 +02:00
parent 616dbe142a
commit ea13f77b00
No known key found for this signature in database
GPG key ID: F07A7D55A2684852
2 changed files with 14 additions and 15 deletions

View file

@ -690,7 +690,7 @@ func (sb *smartBlock) Apply(s *state.State, flags ...ApplyFlag) (err error) {
sb.reportChange(st)
if hasDepIds(sb.Relations(st), &act) {
if hasDepIds(sb.GetRelationLinks(), &act) {
sb.CheckSubscriptions()
}
afterReportChangeTime := time.Now()
@ -1118,7 +1118,7 @@ func (sb *smartBlock) StateAppend(f func(d state.Doc) (s *state.State, err error
})
}
sb.storeFileKeys(s)
if hasDepIds(sb.Relations(s), &act) {
if hasDepIds(sb.GetRelationLinks(), &act) {
sb.CheckSubscriptions()
}
sb.reportChange(s)
@ -1178,8 +1178,7 @@ func (sb *smartBlock) Close() (err error) {
return
}
// todo refactor: use relationLinks instead
func hasDepIds(relations relationutils.Relations, act *undo.Action) bool {
func hasDepIds(relations pbtypes.RelationLinks, act *undo.Action) bool {
if act == nil {
return true
}
@ -1191,8 +1190,8 @@ func hasDepIds(relations relationutils.Relations, act *undo.Action) bool {
return true
}
for k, after := range act.Details.After.Fields {
rel := relations.GetByKey(k)
if rel != nil && len(rel.ObjectTypes) > 0 {
rel := relations.Get(k)
if rel != nil && rel.Format == model.RelationFormat_status || rel.Format == model.RelationFormat_tag || rel.Format == model.RelationFormat_object {
before := act.Details.Before.Fields[k]
// Check that value is actually changed
if before == nil || !before.Equal(after) {

View file

@ -4,6 +4,15 @@ import "github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
type RelationLinks []*model.RelationLink
func (rl RelationLinks) Get(key string) *model.RelationLink {
for _, l := range rl {
if l.Key == key {
return l
}
}
return nil
}
func (rl RelationLinks) Has(key string) bool {
for _, l := range rl {
if l.Key == key {
@ -13,15 +22,6 @@ func (rl RelationLinks) Has(key string) bool {
return false
}
func (rl RelationLinks) Key(id string) (key string, ok bool) {
for _, l := range rl {
if l.Key == id {
return l.Key, true
}
}
return
}
func (rl RelationLinks) Append(l *model.RelationLink) RelationLinks {
return append(rl, l)
}