Improve check in storage service comparator

This commit is contained in:
Fedor Indutny 2025-01-08 18:23:13 -08:00 committed by GitHub
parent a384b40e63
commit 3a1addbfe5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -748,22 +748,30 @@ function doRecordsConflict(
continue; continue;
} }
const isRemoteNullish =
!remoteValue || (Long.isLong(remoteValue) && remoteValue.isZero());
const isLocalNullish =
!localValue || (Long.isLong(localValue) && localValue.isZero());
// Sometimes we get `null` values from Protobuf and they should default to // Sometimes we get `null` values from Protobuf and they should default to
// false, empty string, or 0 for these records we do not count them as // false, empty string, or 0 for these records we do not count them as
// conflicting. // conflicting.
if ( if (isRemoteNullish && isLocalNullish) {
(!remoteValue || (Long.isLong(remoteValue) && remoteValue.isZero())) &&
(!localValue || (Long.isLong(localValue) && localValue.isZero()))
) {
continue; continue;
} }
const areEqual = isEqual(localValue, remoteValue); const areEqual = isEqual(localValue, remoteValue);
if (!areEqual) { if (!areEqual) {
if (isRemoteNullish) {
details.push(`key=${key}: removed`);
} else if (isLocalNullish) {
details.push(`key=${key}: added`);
} else {
details.push(`key=${key}: different values`); details.push(`key=${key}: different values`);
} }
} }
}
return { return {
hasConflict: details.length > 0, hasConflict: details.length > 0,