Skip to content

Commit

Permalink
Merge pull request #1740 from anyproto/GO-4373-remove-sync-relations
Browse files Browse the repository at this point in the history
GO-4373: Remove sync relations
  • Loading branch information
mcrakhman authored Oct 28, 2024
2 parents ee7d145 + 8b0bdfb commit 5d5a711
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/block/editor/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,9 @@ func (s *State) Copy() *State {
}

func (s *State) HasRelation(key string) bool {
for _, rel := range s.relationLinks {
if rel.Key == key {
links := s.GetRelationLinks()
for _, link := range links {
if link.Key == key {
return true
}
}
Expand Down
20 changes: 19 additions & 1 deletion core/syncstatus/detailsupdater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func (u *syncStatusUpdater) updateObjectDetails(syncStatusDetails *syncStatusDet
details = &types.Struct{Fields: map[string]*types.Value{}}
}
if !u.isLayoutSuitableForSyncRelations(details) {
delete(details.Fields, bundle.RelationKeySyncStatus.String())
delete(details.Fields, bundle.RelationKeySyncError.String())
delete(details.Fields, bundle.RelationKeySyncDate.String())
return details, false, nil
}
if fileStatus, ok := details.GetFields()[bundle.RelationKeyFileBackupStatus.String()]; ok {
Expand All @@ -233,10 +236,25 @@ func (u *syncStatusUpdater) setSyncDetails(sb smartblock.SmartBlock, status doma
if !slices.Contains(helper.SyncRelationsSmartblockTypes(), sb.Type()) {
return nil
}
st := sb.NewState()
if !u.isLayoutSuitableForSyncRelations(sb.Details()) {
var syncRelations = []string{
bundle.RelationKeySyncStatus.String(),
bundle.RelationKeySyncError.String(),
bundle.RelationKeySyncDate.String(),
}
removedOnce := false
for _, relation := range syncRelations {
if st.HasRelation(relation) {
removedOnce = true
st.RemoveRelation(relation)
}
}
if removedOnce {
return sb.Apply(st, smartblock.KeepInternalFlags /* do not erase flags */)
}
return nil
}
st := sb.NewState()
if fileStatus, ok := st.Details().GetFields()[bundle.RelationKeyFileBackupStatus.String()]; ok {
status, syncError = getSyncStatusForFile(status, syncError, filesyncstatus.Status(int(fileStatus.GetNumberValue())))
}
Expand Down

0 comments on commit 5d5a711

Please sign in to comment.