Improve speed of document change detection
This commit is contained in:
parent
a1b6d24772
commit
304c0458e8
2 changed files with 30 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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{})
|
||||
|
|
Loading…
Reference in a new issue