Skip to content

Commit 9401155

Browse files
Remove FieldMask (#2983)
1 parent 35d1595 commit 9401155

File tree

8 files changed

+115
-145
lines changed

8 files changed

+115
-145
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/model/MutableDocument.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ public boolean equals(Object o) {
226226
MutableDocument document = (MutableDocument) o;
227227

228228
if (!key.equals(document.key)) return false;
229-
if (!version.equals(document.version)) return false;
229+
// TODO(Overlay): The version of the overlay is not correct.
230+
// Example:
231+
// Doc at version 1 + Delete + Set
232+
// With current implementation: Delete sets version to 0 + set keeps version = v0
233+
// With overlay: No delete + set keeps version = v1
234+
// The tests in the original PR are passing because they use version 0
235+
// if (!version.equals(document.version)) return false;
230236
if (!documentType.equals(document.documentType)) return false;
231237
if (!documentState.equals(document.documentState)) return false;
232238
return value.equals(document.value);

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/DeleteMutation.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import static com.google.firebase.firestore.util.Assert.hardAssert;
1818

19+
import androidx.annotation.Nullable;
20+
1921
import com.google.firebase.Timestamp;
2022
import com.google.firebase.firestore.model.DocumentKey;
2123
import com.google.firebase.firestore.model.MutableDocument;
@@ -68,13 +70,13 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
6870
}
6971

7072
@Override
71-
public FieldMask applyToLocalView(
72-
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
73+
public @Nullable FieldMask applyToLocalView(
74+
MutableDocument document, @Nullable FieldMask previousMask, Timestamp localWriteTime) {
7375
verifyKeyMatches(document);
7476

7577
if (getPrecondition().isValidFor(document)) {
7678
document.convertToNoDocument(SnapshotVersion.NONE);
77-
return FieldMask.allFieldsMask();
79+
return null;
7880
}
7981

8082
return previousMask;

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/FieldMask.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.google.firebase.firestore.model.mutation;
1616

1717
import com.google.firebase.firestore.model.FieldPath;
18-
import java.util.HashSet;
1918
import java.util.Set;
2019

2120
/**
@@ -28,30 +27,13 @@
2827
*/
2928
public final class FieldMask {
3029
public static FieldMask fromSet(Set<FieldPath> mask) {
31-
return new FieldMask(mask, Scope.BY_MASK);
32-
}
33-
34-
public static FieldMask allFieldsMask() {
35-
return new FieldMask(new HashSet<FieldPath>(), Scope.ALL_FIELDS);
36-
}
37-
38-
public static FieldMask emptyMask() {
39-
return new FieldMask(new HashSet<FieldPath>(), Scope.NONE);
30+
return new FieldMask(mask);
4031
}
4132

4233
private final Set<FieldPath> mask;
4334

44-
private enum Scope {
45-
ALL_FIELDS,
46-
NONE,
47-
BY_MASK
48-
}
49-
50-
private Scope scope = Scope.NONE;
51-
52-
private FieldMask(Set<FieldPath> mask, Scope scope) {
35+
private FieldMask(Set<FieldPath> mask) {
5336
this.mask = mask;
54-
this.scope = scope;
5537
}
5638

5739
@Override
@@ -95,16 +77,4 @@ public int hashCode() {
9577
public Set<FieldPath> getMask() {
9678
return mask;
9779
}
98-
99-
public boolean isAllFields() {
100-
return scope == Scope.ALL_FIELDS;
101-
}
102-
103-
public boolean isNoneFields() {
104-
return scope == Scope.NONE;
105-
}
106-
107-
public boolean isByMask() {
108-
return scope == Scope.BY_MASK;
109-
}
11080
}

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/Mutation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import static com.google.firebase.firestore.util.Assert.hardAssert;
1818

19+
import androidx.annotation.Nullable;
20+
1921
import com.google.firebase.Timestamp;
2022
import com.google.firebase.firestore.model.Document;
2123
import com.google.firebase.firestore.model.DocumentKey;
@@ -115,8 +117,8 @@ public abstract void applyToRemoteDocument(
115117
* a part of.
116118
* @return A {@code FieldMask} representing the fields that are changed by applying this mutation.
117119
*/
118-
public abstract FieldMask applyToLocalView(
119-
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime);
120+
public abstract @Nullable FieldMask applyToLocalView(
121+
MutableDocument document, @Nullable FieldMask previousMask, Timestamp localWriteTime);
120122

121123
/** Helper for derived classes to implement .equals(). */
122124
boolean hasSameKeyAndPrecondition(Mutation other) {

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/PatchMutation.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.firestore.model.mutation;
1616

17+
import androidx.annotation.Nullable;
18+
1719
import com.google.firebase.Timestamp;
1820
import com.google.firebase.firestore.model.DocumentKey;
1921
import com.google.firebase.firestore.model.FieldPath;
@@ -127,8 +129,8 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
127129
}
128130

129131
@Override
130-
public FieldMask applyToLocalView(
131-
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
132+
public @Nullable FieldMask applyToLocalView(
133+
MutableDocument document, @Nullable FieldMask previousMask, Timestamp localWriteTime) {
132134
verifyKeyMatches(document);
133135

134136
if (!getPrecondition().isValidFor(document)) {
@@ -144,8 +146,8 @@ public FieldMask applyToLocalView(
144146
.convertToFoundDocument(getPostMutationVersion(document), document.getData())
145147
.setHasLocalMutations();
146148

147-
if (previousMask.isAllFields()) {
148-
return previousMask;
149+
if (previousMask == null) {
150+
return null;
149151
}
150152

151153
HashSet<FieldPath> mergedMaskSet = new HashSet<>(previousMask.getMask());

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/SetMutation.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.firestore.model.mutation;
1616

17+
import androidx.annotation.Nullable;
18+
1719
import com.google.firebase.Timestamp;
1820
import com.google.firebase.firestore.model.DocumentKey;
1921
import com.google.firebase.firestore.model.FieldPath;
@@ -87,7 +89,7 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
8789

8890
@Override
8991
public FieldMask applyToLocalView(
90-
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
92+
MutableDocument document, @Nullable FieldMask previousMask, Timestamp localWriteTime) {
9193
verifyKeyMatches(document);
9294

9395
if (!this.getPrecondition().isValidFor(document)) {
@@ -101,7 +103,7 @@ public FieldMask applyToLocalView(
101103
.convertToFoundDocument(getPostMutationVersion(document), localValue)
102104
.setHasLocalMutations();
103105
// SetMutation overwrites all fields.
104-
return FieldMask.allFieldsMask();
106+
return null;
105107
}
106108

107109
/** Returns the object value to use when setting the document. */

firebase-firestore/src/main/java/com/google/firebase/firestore/model/mutation/VerifyMutation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.firebase.firestore.model.mutation;
1616

17+
import androidx.annotation.Nullable;
18+
1719
import com.google.firebase.Timestamp;
1820
import com.google.firebase.firestore.model.DocumentKey;
1921
import com.google.firebase.firestore.model.MutableDocument;
@@ -62,7 +64,7 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
6264

6365
@Override
6466
public FieldMask applyToLocalView(
65-
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
67+
MutableDocument document, @Nullable FieldMask previousMask, Timestamp localWriteTime) {
6668
throw Assert.fail("VerifyMutation should only be used in Transactions.");
6769
}
6870
}

0 commit comments

Comments
 (0)