diff --git a/db/document.go b/db/document.go index 04756be1..ea404f4c 100644 --- a/db/document.go +++ b/db/document.go @@ -18,7 +18,6 @@ import ( "fmt" "context" - "reflect" "github.com/abcum/surreal/kvs" "github.com/abcum/surreal/sql" @@ -207,7 +206,7 @@ func (d *document) forced(ctx context.Context) bool { } func (d *document) hasChanged(ctx context.Context) bool { - return reflect.DeepEqual(d.initial, d.current) == false + return d.initial.Same(d.current) == false } func (d *document) shouldDrop(ctx context.Context) (bool, error) { diff --git a/util/data/data.go b/util/data/data.go index b4d07ea7..eb9fce16 100644 --- a/util/data/data.go +++ b/util/data/data.go @@ -913,6 +913,35 @@ func (d *Doc) Dec(value interface{}, path ...string) (*Doc, error) { // -------------------------------------------------------------------------------- +func (d *Doc) Same(n *Doc) bool { + + switch a := d.data.(type) { + case []interface{}: + switch b := n.data.(type) { + case map[string]interface{}: + return false + case []interface{}: + if len(a) != len(b) { + return false + } + break + } + case map[string]interface{}: + switch b := n.data.(type) { + case []interface{}: + return false + case map[string]interface{}: + if len(a) != len(b) { + return false + } + break + } + } + + return reflect.DeepEqual(d, n) + +} + func (d *Doc) Diff(n *Doc) map[string]interface{} { var initial = make(map[string]interface{})