@@ -53,7 +53,7 @@ func (delta *Delta) run(ctx context.Context, actualCh, desiredCh <-chan database
53
53
desired := EntitiesById {} // only read from desiredCh (so far)
54
54
55
55
var update EntitiesById
56
- if delta .Subject .WithChecksum () {
56
+ if _ , ok := delta . Subject . Entity ().(contracts. Equaler ); ok || delta .Subject .WithChecksum () {
57
57
update = EntitiesById {} // read from actualCh and desiredCh with mismatching checksums
58
58
}
59
59
@@ -70,7 +70,7 @@ func (delta *Delta) run(ctx context.Context, actualCh, desiredCh <-chan database
70
70
id := actualValue .ID ().String ()
71
71
if desiredValue , ok := desired [id ]; ok {
72
72
delete (desired , id )
73
- if update != nil && ! checksumsMatch (actualValue , desiredValue ) {
73
+ if update != nil && ! entitiesEqual (actualValue , desiredValue ) {
74
74
update [id ] = desiredValue
75
75
}
76
76
} else {
@@ -88,7 +88,7 @@ func (delta *Delta) run(ctx context.Context, actualCh, desiredCh <-chan database
88
88
id := desiredValue .ID ().String ()
89
89
if actualValue , ok := actual [id ]; ok {
90
90
delete (actual , id )
91
- if update != nil && ! checksumsMatch (actualValue , desiredValue ) {
91
+ if update != nil && ! entitiesEqual (actualValue , desiredValue ) {
92
92
update [id ] = desiredValue
93
93
}
94
94
} else {
@@ -117,8 +117,14 @@ func (delta *Delta) run(ctx context.Context, actualCh, desiredCh <-chan database
117
117
zap .Int ("delete" , len (delta .Delete )))
118
118
}
119
119
120
- // checksumsMatch returns whether the checksums of two entities are the same.
121
- // Both entities must implement contracts.Checksumer.
122
- func checksumsMatch (a , b database.Entity ) bool {
123
- return cmp .Equal (a .(contracts.Checksumer ).Checksum (), b .(contracts.Checksumer ).Checksum ())
120
+ // entitiesEqual returns whether the two entities are equal either based on their checksum or by comparing them.
121
+ //
122
+ // Both entities must either implement contracts.Checksumer or contracts.Equaler for this to work. If neither
123
+ // interface is implemented nor if both entities don't implement the same interface, this function will panic.
124
+ func entitiesEqual (a , b database.Entity ) bool {
125
+ if _ , ok := a .(contracts.Checksumer ); ok {
126
+ return cmp .Equal (a .(contracts.Checksumer ).Checksum (), b .(contracts.Checksumer ).Checksum ())
127
+ }
128
+
129
+ return a .(contracts.Equaler ).Equal (b )
124
130
}
0 commit comments