diff --git a/db/document.go b/db/document.go index 67d4dcc5..656c915f 100644 --- a/db/document.go +++ b/db/document.go @@ -22,6 +22,7 @@ import ( "github.com/abcum/surreal/kvs" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/data" + "github.com/abcum/surreal/util/diff" "github.com/abcum/surreal/util/indx" "github.com/abcum/surreal/util/keys" ) @@ -205,6 +206,13 @@ func (d *document) forced(ctx context.Context) bool { 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) { // Check whether it is specified diff --git a/db/merge.go b/db/merge.go index 7311896e..0e500d16 100644 --- a/db/merge.go +++ b/db/merge.go @@ -18,7 +18,6 @@ import ( "sort" "context" - "reflect" "github.com/abcum/surreal/cnf" "github.com/abcum/surreal/sql" @@ -75,7 +74,7 @@ func (d *document) merge(ctx context.Context, met method, data sql.Expr) (err er return } - d.changed = !reflect.DeepEqual(d.initial, d.current) + d.changed = d.hasChanged(ctx) return