Diff the document properly to detect any changes
This commit is contained in:
parent
1b4c1bd094
commit
bd8c6fddb2
2 changed files with 9 additions and 2 deletions
|
@ -22,6 +22,7 @@ import (
|
||||||
"github.com/abcum/surreal/kvs"
|
"github.com/abcum/surreal/kvs"
|
||||||
"github.com/abcum/surreal/sql"
|
"github.com/abcum/surreal/sql"
|
||||||
"github.com/abcum/surreal/util/data"
|
"github.com/abcum/surreal/util/data"
|
||||||
|
"github.com/abcum/surreal/util/diff"
|
||||||
"github.com/abcum/surreal/util/indx"
|
"github.com/abcum/surreal/util/indx"
|
||||||
"github.com/abcum/surreal/util/keys"
|
"github.com/abcum/surreal/util/keys"
|
||||||
)
|
)
|
||||||
|
@ -205,6 +206,13 @@ func (d *document) forced(ctx context.Context) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *document) hasChanged(ctx context.Context) bool {
|
||||||
|
a, _ := d.initial.Data().(map[string]interface{})
|
||||||
|
b, _ := d.current.Data().(map[string]interface{})
|
||||||
|
c := diff.Diff(a, b)
|
||||||
|
return len(c) > 0
|
||||||
|
}
|
||||||
|
|
||||||
func (d *document) shouldDrop(ctx context.Context) (bool, error) {
|
func (d *document) shouldDrop(ctx context.Context) (bool, error) {
|
||||||
|
|
||||||
// Check whether it is specified
|
// Check whether it is specified
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
"reflect"
|
|
||||||
|
|
||||||
"github.com/abcum/surreal/cnf"
|
"github.com/abcum/surreal/cnf"
|
||||||
"github.com/abcum/surreal/sql"
|
"github.com/abcum/surreal/sql"
|
||||||
|
@ -75,7 +74,7 @@ func (d *document) merge(ctx context.Context, met method, data sql.Expr) (err er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
d.changed = !reflect.DeepEqual(d.initial, d.current)
|
d.changed = d.hasChanged(ctx)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue