Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions core/block/editor/smartblock/smartblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,16 +926,6 @@ func (sb *smartBlock) Apply(s *state.State, flags ...ApplyFlag) (err error) {

func (sb *smartBlock) ResetToVersion(s *state.State) (err error) {
source.NewSubObjectsAndProfileLinksMigration(sb.Type(), sb.space, sb.currentParticipantId, sb.spaceIndex, sb.formatFetcher).Migrate(s)
// Ensure bundled relation links are present for all bundled detail keys.
// Without this, imported states may lack relation links for details like setOf,
// producing a RelationRemove change that wipes the detail on replay (GO-7217).
var relKeys []domain.RelationKey
for k := range s.Details().Iterate() {
if bundle.HasRelation(k) {
relKeys = append(relKeys, k)
}
}
s.AddBundledRelationLinks(relKeys...)
s.SetParent(sb.Doc.(*state.State))
sb.storeFileKeys(s)
sb.injectLocalDetails(s)
Expand Down
63 changes: 5 additions & 58 deletions core/block/editor/state/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func NewDocFromSnapshot(rootId string, snapshot *pb.ChangeSnapshot, opts ...Snap
rootId: rootId,
blocks: blocks,
details: details,
relationLinks: snapshot.Data.RelationLinks,
objectTypeKeys: migrateObjectTypeIDsToKeys(snapshot.Data.ObjectTypes),
fileKeys: fileKeys,
store: snapshot.Data.Collections,
Expand Down Expand Up @@ -277,17 +276,14 @@ func (s *State) changeBlockDetailsUnset(unset *pb.ChangeDetailsUnset) error {
return nil
}

// changeRelationAdd is kept for backward compatibility to parse RelationAdd changes from
// existing trees. Object-level relationLinks were removed (GO-4284), so it is a no-op.
func (s *State) changeRelationAdd(add *pb.ChangeRelationAdd) error {
rl := s.getRelationLinks()
for _, r := range add.RelationLinks {
if !rl.Has(r.Key) {
rl = rl.Append(r)
}
}
s.relationLinks = rl
return nil
}

// changeRelationRemove parses a legacy RelationRemove change. Relations are now tracked by
// details, so removing the relation removes its detail value (and featured entry).
func (s *State) changeRelationRemove(rem *pb.ChangeRelationRemove) error {
s.RemoveRelation(slice.StringsInto[domain.RelationKey](rem.RelationKey)...)
return nil
Expand Down Expand Up @@ -467,8 +463,7 @@ func (s *State) GetChanges() []*pb.ChangeContent {

func (s *State) fillChanges(msgs []simple.EventMessage) {
var updMsgs = make([]*pb.EventMessage, 0, len(msgs))
var delIds, delRelIds []string
var newRelLinks pbtypes.RelationLinks
var delIds []string
var structMsgs = make([]*pb.EventBlockSetChildrenIds, 0, len(msgs))
var b1, b2 []byte
for i, msg := range msgs {
Expand Down Expand Up @@ -547,10 +542,6 @@ func (s *State) fillChanges(msgs []simple.EventMessage) {
updMsgs = append(updMsgs, msg.Msg)
case *pb.EventMessageValueOfBlockDataViewGroupOrderUpdate:
updMsgs = append(updMsgs, msg.Msg)
case *pb.EventMessageValueOfObjectRelationsAmend:
newRelLinks = append(newRelLinks, msg.Msg.GetObjectRelationsAmend().RelationLinks...)
case *pb.EventMessageValueOfObjectRelationsRemove:
delRelIds = append(delRelIds, msg.Msg.GetObjectRelationsRemove().RelationKeys...)
case *pb.EventMessageValueOfBlockDataViewObjectOrderUpdate:
updMsgs = append(updMsgs, msg.Msg)
case *pb.EventMessageValueOfBlockDataviewViewUpdate:
Expand Down Expand Up @@ -580,30 +571,6 @@ func (s *State) fillChanges(msgs []simple.EventMessage) {
},
})
}
if len(newRelLinks) > 0 {
filteredRelationsLinks := s.filterLocalAndDerivedRelations(newRelLinks)
if len(filteredRelationsLinks) > 0 {
cb.AddChange(&pb.ChangeContent{
Value: &pb.ChangeContentValueOfRelationAdd{
RelationAdd: &pb.ChangeRelationAdd{
RelationLinks: filteredRelationsLinks,
},
},
})
}
}
if len(delRelIds) > 0 {
filteredRelationsKeys := s.filterLocalAndDerivedRelationsByKey(delRelIds)
if len(filteredRelationsKeys) > 0 {
cb.AddChange(&pb.ChangeContent{
Value: &pb.ChangeContentValueOfRelationRemove{
RelationRemove: &pb.ChangeRelationRemove{
RelationKey: filteredRelationsKeys,
},
},
})
}
}
if len(updMsgs) > 0 {
cb.AddChange(&pb.ChangeContent{
Value: &pb.ChangeContentValueOfBlockUpdate{
Expand All @@ -623,26 +590,6 @@ func (s *State) fillChanges(msgs []simple.EventMessage) {
s.changes = append(s.changes, s.makeDeviceInfoChanges()...)
}

func (s *State) filterLocalAndDerivedRelations(newRelLinks pbtypes.RelationLinks) pbtypes.RelationLinks {
var relLinksWithoutLocal pbtypes.RelationLinks
for _, link := range newRelLinks {
if !slices.Contains(bundle.LocalAndDerivedRelationKeys, domain.RelationKey(link.Key)) {
relLinksWithoutLocal = relLinksWithoutLocal.Append(link)
}
}
return relLinksWithoutLocal
}

func (s *State) filterLocalAndDerivedRelationsByKey(relationKeys []string) []string {
var relKeysWithoutLocal []string
for _, key := range relationKeys {
if !slices.Contains(bundle.LocalAndDerivedRelationKeys, domain.RelationKey(key)) {
relKeysWithoutLocal = append(relKeysWithoutLocal, key)
}
}
return relKeysWithoutLocal
}

func (s *State) fillStructureChanges(cb *changeBuilder, msgs []*pb.EventBlockSetChildrenIds) {
for _, msg := range msgs {
s.makeStructureChanges(cb, msg)
Expand Down
76 changes: 0 additions & 76 deletions core/block/editor/state/change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,82 +695,6 @@ func Test_ApplyChange(t *testing.T) {
})
}

func TestRelationChanges(t *testing.T) {
a := NewDoc("root", nil).(*State)
a.relationLinks = []*model.RelationLink{{Key: "1"}, {Key: "2"}, {Key: "3"}}
ac := a.Copy()
b := a.NewState()
b.relationLinks = []*model.RelationLink{{Key: "3"}, {Key: "4"}, {Key: "5"}}
_, _, err := ApplyState("", b, false)
require.NoError(t, err)
chs := a.GetChanges()
require.NoError(t, ac.ApplyChange(chs...))
require.Equal(t, a.relationLinks, ac.relationLinks)
}

func TestLocalRelationChanges(t *testing.T) {
t.Run("local relation added", func(t *testing.T) {
// given
a := NewDoc("root", nil).(*State)
a.relationLinks = []*model.RelationLink{}
b := a.NewState()
b.relationLinks = []*model.RelationLink{{Key: bundle.RelationKeySyncStatus.String(), Format: model.RelationFormat_number}}

// when
_, _, err := ApplyState("", b, false)
require.NoError(t, err)
chs := a.GetChanges()

// then
require.Len(t, chs, 0)
})
t.Run("local relation removed", func(t *testing.T) {
// given
a := NewDoc("root", nil).(*State)
a.relationLinks = []*model.RelationLink{{Key: bundle.RelationKeySyncStatus.String(), Format: model.RelationFormat_number}}
b := a.NewState()
b.relationLinks = []*model.RelationLink{}

// when
_, _, err := ApplyState("", b, false)
require.NoError(t, err)
chs := a.GetChanges()

// then
require.Len(t, chs, 0)
})
t.Run("derived relation added", func(t *testing.T) {
// given
a := NewDoc("root", nil).(*State)
a.relationLinks = []*model.RelationLink{}
b := a.NewState()
b.relationLinks = []*model.RelationLink{{Key: bundle.RelationKeySpaceId.String(), Format: model.RelationFormat_longtext}}

// when
_, _, err := ApplyState("", b, false)
require.NoError(t, err)
chs := a.GetChanges()

// then
require.Len(t, chs, 0)
})
t.Run("derived relation removed", func(t *testing.T) {
// given
a := NewDoc("root", nil).(*State)
a.relationLinks = []*model.RelationLink{{Key: bundle.RelationKeySpaceId.String(), Format: model.RelationFormat_longtext}}
b := a.NewState()
b.relationLinks = []*model.RelationLink{}

// when
_, _, err := ApplyState("", b, false)
require.NoError(t, err)
chs := a.GetChanges()

// then
require.Len(t, chs, 0)
})
}

func TestRootBlockChanges(t *testing.T) {
a := NewDoc("root", nil).(*State)
s := a.NewState()
Expand Down
14 changes: 0 additions & 14 deletions core/block/editor/state/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/anyproto/anytype-heart/core/relationutils"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/util/pbtypes"
"github.com/anyproto/anytype-heart/util/slice"
)

Expand Down Expand Up @@ -162,19 +161,6 @@ func (s *State) SetLocalDetail(key domain.RelationKey, value domain.Value) {
// details removers

func (s *State) RemoveRelation(keys ...domain.RelationKey) {
// TODO: GO-4284 remove logic regarding relationLinks
relLinks := s.getRelationLinks()
relLinksFiltered := make(pbtypes.RelationLinks, 0, len(relLinks))
for _, link := range relLinks {
if slice.FindPos(keys, domain.RelationKey(link.Key)) >= 0 {
continue
}
relLinksFiltered = append(relLinksFiltered, &model.RelationLink{
Key: link.Key,
Format: link.Format,
})
}
s.relationLinks = relLinksFiltered
// remove detail value
s.RemoveDetail(keys...)
// remove from the list of featured relations
Expand Down
Loading
Loading