From ea13f77b00b60552eb5fb51509402c75047ab4c8 Mon Sep 17 00:00:00 2001 From: Roman Khafizianov Date: Tue, 18 Oct 2022 12:01:57 +0200 Subject: [PATCH] fix hasDepIds to look on RelationLinks instead of Relations --- core/block/editor/smartblock/smartblock.go | 11 +++++------ util/pbtypes/relationlink.go | 18 +++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/core/block/editor/smartblock/smartblock.go b/core/block/editor/smartblock/smartblock.go index f275440fe..0b928ddb2 100644 --- a/core/block/editor/smartblock/smartblock.go +++ b/core/block/editor/smartblock/smartblock.go @@ -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) { diff --git a/util/pbtypes/relationlink.go b/util/pbtypes/relationlink.go index be84f01ae..afc23d37c 100644 --- a/util/pbtypes/relationlink.go +++ b/util/pbtypes/relationlink.go @@ -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) }