Skip to content

Commit

Permalink
Basic test-suite now working with new CRDT structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Sambigeara committed Oct 1, 2022
1 parent 2f4864e commit bba2eef
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 390 deletions.
14 changes: 0 additions & 14 deletions pkg/service/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package service

import (
"context"
"log"
)

type RefreshKey struct {
Expand Down Expand Up @@ -34,18 +33,6 @@ func (r *DBListRepo) Start(client Client) error {
go func() {
for {
select {
//case wal := <-reorderAndReplayChan:
// if err := r.Replay(wal); err != nil {
// errChan <- err
// return
// }
// changedKeys, allowOverride := getChangedListItemKeysFromWal(wal)
// go func() {
// inputEvtsChan <- RefreshKey{
// ChangedKeys: changedKeys,
// AllowOverride: allowOverride,
// }
// }()
case wal := <-replayChan:
if err := r.Replay(wal); err != nil {
errChan <- err
Expand Down Expand Up @@ -74,7 +61,6 @@ func (r *DBListRepo) Start(client Client) error {
if finishErr := r.finish(isPurge); finishErr != nil {
errChan <- finishErr
}
log.Printf("%v", r.vectorClock)
errChan <- err
return
}
Expand Down
24 changes: 7 additions & 17 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,30 +311,20 @@ func (r *DBListRepo) UpdateNote(note []byte, item *ListItem) error {

// Delete will remove an existing ListItem
func (r *DBListRepo) Delete(item *ListItem) (string, error) {
var childKey, matchChildKey string
if c := item.child; c != nil {
childKey = c.key
}

e := r.newEventLogFromListItem(DeleteEvent, item, true)

r.addEventLog(e)

ue := r.newEventLogFromListItem(UpdateEvent, item, false)
ue.ListItemKey = item.key
ue.TargetListItemKey = childKey
ue.Line = item.rawLine
ue.Note = item.Note

r.addEventLog(e)
r.addUndoLog(ue, e)

// We use matchChild to set the next "current key", otherwise, if we delete the final matched item, which happens
// to have a child in the full (un-matched) set, it will default to that on the return (confusing because it will
// not match the current specified search groups)
if item.matchChild != nil {
matchChildKey = item.matchChild.key
return item.matchChild.key, nil
}
return matchChildKey, nil
return "", nil
}

// MoveUp will swop a ListItem with the ListItem directly above it, taking visibility and
Expand Down Expand Up @@ -401,12 +391,12 @@ func (r *DBListRepo) ToggleVisibility(item *ListItem) (string, error) {
focusedItemKey = item.matchChild.key
}
}
item.IsHidden = newIsHidden
e := r.newEventLogFromListItem(UpdateEvent, item, true)
e.IsHidden = newIsHidden
r.addEventLog(e)

item.IsHidden = !newIsHidden
ue := r.newEventLogFromListItem(UpdateEvent, item, false)
ue.IsHidden = !newIsHidden
r.addUndoLog(ue, e)

return focusedItemKey, nil
Expand All @@ -422,7 +412,7 @@ func (r *DBListRepo) Undo() (string, error) {
// UUID and LamportTimestamp of the new event. However, we need to maintain the old key in order to map
// to the old ListItem in the caches
r.incLocalVectorDT()
e.setVectorDT(r.uuid, r.getLocalVectorDT())
e.VectorClock = r.getLocalVectorClockCopy()

item, err := r.addEventLog(e)
r.eventLogger.curIdx--
Expand All @@ -442,7 +432,7 @@ func (r *DBListRepo) Redo() (string, error) {
// UUID and LamportTimestamp of the new event. However, we need to maintain the old key in order to map
// to the old ListItem in the caches
r.incLocalVectorDT()
e.setVectorDT(r.uuid, r.getLocalVectorDT())
e.VectorClock = r.getLocalVectorClockCopy()

item, err := r.addEventLog(e)
r.eventLogger.curIdx++
Expand Down
Loading

0 comments on commit bba2eef

Please sign in to comment.