mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-11 02:13:49 +09:00
Any-sync remove printlns and fix condition
This commit is contained in:
parent
b7c4bf8f1e
commit
fa52eb413d
2 changed files with 7 additions and 13 deletions
|
@ -1,7 +1,6 @@
|
|||
package settingsstate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/anytypeio/any-sync/commonspace/object/tree/objecttree"
|
||||
"github.com/anytypeio/any-sync/commonspace/spacesyncproto"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
|
@ -31,7 +30,7 @@ func (s *stateBuilder) Build(tr objecttree.ObjectTree, oldState *State) (state *
|
|||
}
|
||||
|
||||
process := func(change *objecttree.Change) bool {
|
||||
state = s.processChange(change, rootId, startId, state)
|
||||
state = s.processChange(change, rootId, state)
|
||||
state.LastIteratedId = change.Id
|
||||
return true
|
||||
}
|
||||
|
@ -43,14 +42,13 @@ func (s *stateBuilder) Build(tr objecttree.ObjectTree, oldState *State) (state *
|
|||
}
|
||||
return deleteChange, nil
|
||||
}
|
||||
|
||||
err = tr.IterateFrom(startId, convert, process)
|
||||
return
|
||||
}
|
||||
|
||||
func (s *stateBuilder) processChange(change *objecttree.Change, rootId, startId string, state *State) *State {
|
||||
func (s *stateBuilder) processChange(change *objecttree.Change, rootId string, state *State) *State {
|
||||
// ignoring root change which has empty model or startId change
|
||||
if change.Model == nil || state.LastIteratedId == startId {
|
||||
if change.Model == nil || state.LastIteratedId == change.Id {
|
||||
return state
|
||||
}
|
||||
|
||||
|
@ -67,12 +65,10 @@ func (s *stateBuilder) processChange(change *objecttree.Change, rootId, startId
|
|||
|
||||
// otherwise getting data from content
|
||||
for _, cnt := range deleteChange.Content {
|
||||
fmt.Println(cnt.GetSpaceDelete() != nil)
|
||||
switch {
|
||||
case cnt.GetObjectDelete() != nil:
|
||||
state.DeletedIds = append(state.DeletedIds, cnt.GetObjectDelete().GetId())
|
||||
case cnt.GetSpaceDelete() != nil:
|
||||
fmt.Println(cnt.GetSpaceDelete().GetDeleterPeerId())
|
||||
state.DeleterId = cnt.GetSpaceDelete().GetDeleterPeerId()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) {
|
|||
|
||||
t.Run("empty model", func(t *testing.T) {
|
||||
ch := &objecttree.Change{}
|
||||
startId := "startId"
|
||||
newSt := sb.processChange(ch, rootId, startId, &State{
|
||||
newSt := sb.processChange(ch, rootId, &State{
|
||||
DeletedIds: []string{deletedId},
|
||||
})
|
||||
require.Equal(t, []string{deletedId}, newSt.DeletedIds)
|
||||
|
@ -34,7 +33,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) {
|
|||
}
|
||||
ch.Id = "startId"
|
||||
startId := "startId"
|
||||
newSt := sb.processChange(ch, rootId, startId, &State{
|
||||
newSt := sb.processChange(ch, rootId, &State{
|
||||
DeletedIds: []string{deletedId},
|
||||
LastIteratedId: startId,
|
||||
})
|
||||
|
@ -50,7 +49,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) {
|
|||
},
|
||||
}
|
||||
ch.Id = "rootId"
|
||||
newSt := sb.processChange(ch, rootId, rootId, &State{})
|
||||
newSt := sb.processChange(ch, rootId, &State{})
|
||||
require.Equal(t, []string{"id1", "id2"}, newSt.DeletedIds)
|
||||
require.Equal(t, "peerId", newSt.DeleterId)
|
||||
})
|
||||
|
@ -65,8 +64,7 @@ func TestStateBuilder_ProcessChange(t *testing.T) {
|
|||
},
|
||||
}
|
||||
ch.Id = "someId"
|
||||
startId := "startId"
|
||||
newSt := sb.processChange(ch, rootId, startId, &State{})
|
||||
newSt := sb.processChange(ch, rootId, &State{})
|
||||
require.Equal(t, []string{deletedId}, newSt.DeletedIds)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue