Skip to content

Commit 35d1595

Browse files
committed
Review.
1 parent 9a07b34 commit 35d1595

File tree

10 files changed

+447
-530
lines changed

10 files changed

+447
-530
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/local/LocalDocumentsView.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
210210
document = MutableDocument.newInvalidDocument(key);
211211
remoteDocuments = remoteDocuments.insert(key, document);
212212
}
213-
// TODO(Overlay): Here we should be reading squashed mutation and apply that instead.
213+
// TODO(Overlay): Here we should be reading overlay mutation and apply that instead.
214214
mutation.applyToLocalView(
215-
document, batch.getLocalWriteTime(), FieldMask.fromSet(new HashSet<>()));
215+
document, FieldMask.fromSet(new HashSet<>()), batch.getLocalWriteTime());
216216
if (!document.isFoundDocument()) {
217217
remoteDocuments = remoteDocuments.remove(key);
218218
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public int hashCode() {
261261
@Override
262262
@NonNull
263263
public String toString() {
264-
return "ObjectValue{" + "internalValue=" + buildProto() + '}';
264+
return "ObjectValue{" + "internalValue=" + Values.canonicalId(buildProto()) + '}';
265265
}
266266

267267
@NonNull

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616

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

19-
import androidx.annotation.Nullable;
2019
import com.google.firebase.Timestamp;
2120
import com.google.firebase.firestore.model.DocumentKey;
2221
import com.google.firebase.firestore.model.MutableDocument;
23-
import com.google.firebase.firestore.model.ObjectValue;
2422
import com.google.firebase.firestore.model.SnapshotVersion;
2523

2624
/** Represents a Delete operation */
@@ -71,25 +69,14 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
7169

7270
@Override
7371
public FieldMask applyToLocalView(
74-
MutableDocument document, Timestamp localWriteTime, FieldMask mask) {
72+
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
7573
verifyKeyMatches(document);
7674

7775
if (getPrecondition().isValidFor(document)) {
7876
document.convertToNoDocument(SnapshotVersion.NONE);
7977
return FieldMask.allFieldsMask();
8078
}
8179

82-
return mask;
80+
return previousMask;
8381
}
84-
85-
@Nullable
86-
protected ObjectValue getValue() {
87-
return null;
88-
}
89-
90-
@Nullable
91-
protected FieldMask getMask() {
92-
return null;
93-
}
94-
;
9582
}

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

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

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

19-
import androidx.annotation.Nullable;
2019
import com.google.firebase.Timestamp;
2120
import com.google.firebase.firestore.model.Document;
2221
import com.google.firebase.firestore.model.DocumentKey;
@@ -111,13 +110,13 @@ public abstract void applyToRemoteDocument(
111110
* modified.
112111
*
113112
* @param document The document to mutate.
113+
* @param previousMask The fields that have been updated before applying this mutation.
114114
* @param localWriteTime A timestamp indicating the local write time of the batch this mutation is
115115
* a part of.
116-
* @param mask The fields that have been updated before applying this mutation.
117116
* @return A {@code FieldMask} representing the fields that are changed by applying this mutation.
118117
*/
119118
public abstract FieldMask applyToLocalView(
120-
MutableDocument document, Timestamp localWriteTime, FieldMask mask);
119+
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime);
121120

122121
/** Helper for derived classes to implement .equals(). */
123122
boolean hasSameKeyAndPrecondition(Mutation other) {
@@ -188,12 +187,10 @@ protected Map<FieldPath, Value> serverTransformResults(
188187
*
189188
* @param localWriteTime The local time of the mutation (used to generate ServerTimestampValues).
190189
* @param mutableDocument The document to apply transforms on.
191-
* @param mutation The mutation to be applied to {@code mutableDocument} to get field values on
192-
* which transforms will be applied on.
193190
* @return A map of fields to transform results.
194191
*/
195192
protected Map<FieldPath, Value> localTransformResults(
196-
Timestamp localWriteTime, MutableDocument mutableDocument, Mutation mutation) {
193+
Timestamp localWriteTime, MutableDocument mutableDocument) {
197194
Map<FieldPath, Value> transformResults = new HashMap<>(fieldTransforms.size());
198195
for (FieldTransform fieldTransform : fieldTransforms) {
199196
TransformOperation transform = fieldTransform.getOperation();
@@ -204,14 +201,6 @@ protected Map<FieldPath, Value> localTransformResults(
204201
return transformResults;
205202
}
206203

207-
protected List<FieldPath> getFieldTransformPaths() {
208-
List<FieldPath> result = new ArrayList<>();
209-
for (FieldTransform fieldTransform : fieldTransforms) {
210-
result.add(fieldTransform.getFieldPath());
211-
}
212-
return result;
213-
}
214-
215204
public ObjectValue extractTransformBaseValue(Document document) {
216205
ObjectValue baseObject = null;
217206

@@ -228,10 +217,4 @@ public ObjectValue extractTransformBaseValue(Document document) {
228217

229218
return baseObject;
230219
}
231-
232-
@Nullable
233-
protected abstract ObjectValue getValue();
234-
235-
@Nullable
236-
protected abstract FieldMask getMask();
237220
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ public void applyToLocalView(MutableDocument document) {
105105
for (int i = 0; i < baseMutations.size(); i++) {
106106
Mutation mutation = baseMutations.get(i);
107107
if (mutation.getKey().equals(document.getKey())) {
108-
mutatedFields = mutation.applyToLocalView(document, localWriteTime, mutatedFields);
108+
mutatedFields = mutation.applyToLocalView(document, mutatedFields, localWriteTime);
109109
}
110110
}
111111

112112
// Second, apply all user-provided mutations.
113113
for (int i = 0; i < mutations.size(); i++) {
114114
Mutation mutation = mutations.get(i);
115115
if (mutation.getKey().equals(document.getKey())) {
116-
mutatedFields = mutation.applyToLocalView(document, localWriteTime, mutatedFields);
116+
mutatedFields = mutation.applyToLocalView(document, mutatedFields, localWriteTime);
117117
}
118118
}
119119

120-
// TODO(Overlay): Calculate squashed mutation here.
120+
// TODO(Overlay): Calculate overlay mutation here.
121121
}
122122

123123
/** Computes the local view for all provided documents given the mutations in this batch. */

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
128128

129129
@Override
130130
public FieldMask applyToLocalView(
131-
MutableDocument document, Timestamp localWriteTime, FieldMask mask) {
131+
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
132132
verifyKeyMatches(document);
133133

134134
if (!getPrecondition().isValidFor(document)) {
135-
return mask;
135+
return previousMask;
136136
}
137137

138-
Map<FieldPath, Value> transformResults = localTransformResults(localWriteTime, document, null);
138+
Map<FieldPath, Value> transformResults = localTransformResults(localWriteTime, document);
139139
Map<FieldPath, Value> patches = getPatch();
140140
ObjectValue value = document.getData();
141141
value.setAll(patches);
@@ -144,16 +144,24 @@ public FieldMask applyToLocalView(
144144
.convertToFoundDocument(getPostMutationVersion(document), document.getData())
145145
.setHasLocalMutations();
146146

147-
if (mask.isAllFields()) {
148-
return mask;
147+
if (previousMask.isAllFields()) {
148+
return previousMask;
149149
}
150150

151-
HashSet<FieldPath> mergedMaskSet = new HashSet<>(mask.getMask());
151+
HashSet<FieldPath> mergedMaskSet = new HashSet<>(previousMask.getMask());
152152
mergedMaskSet.addAll(this.mask.getMask());
153153
mergedMaskSet.addAll(getFieldTransformPaths());
154154
return FieldMask.fromSet(mergedMaskSet);
155155
}
156156

157+
private List<FieldPath> getFieldTransformPaths() {
158+
List<FieldPath> result = new ArrayList<>();
159+
for (FieldTransform fieldTransform : getFieldTransforms()) {
160+
result.add(fieldTransform.getFieldPath());
161+
}
162+
return result;
163+
}
164+
157165
private Map<FieldPath, Value> getPatch() {
158166
Map<FieldPath, Value> result = new HashMap<>();
159167
for (FieldPath path : mask.getMask()) {

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

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

17-
import androidx.annotation.Nullable;
1817
import com.google.firebase.Timestamp;
1918
import com.google.firebase.firestore.model.DocumentKey;
2019
import com.google.firebase.firestore.model.FieldPath;
@@ -88,14 +87,14 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
8887

8988
@Override
9089
public FieldMask applyToLocalView(
91-
MutableDocument document, Timestamp localWriteTime, FieldMask mask) {
90+
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
9291
verifyKeyMatches(document);
9392

9493
if (!this.getPrecondition().isValidFor(document)) {
95-
return mask;
94+
return previousMask;
9695
}
9796

98-
Map<FieldPath, Value> transformResults = localTransformResults(localWriteTime, document, null);
97+
Map<FieldPath, Value> transformResults = localTransformResults(localWriteTime, document);
9998
ObjectValue localValue = value.clone();
10099
localValue.setAll(transformResults);
101100
document
@@ -109,9 +108,4 @@ public FieldMask applyToLocalView(
109108
public ObjectValue getValue() {
110109
return value;
111110
}
112-
113-
@Nullable
114-
protected FieldMask getMask() {
115-
return null;
116-
}
117111
}

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

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

17-
import androidx.annotation.Nullable;
1817
import com.google.firebase.Timestamp;
1918
import com.google.firebase.firestore.model.DocumentKey;
2019
import com.google.firebase.firestore.model.MutableDocument;
21-
import com.google.firebase.firestore.model.ObjectValue;
2220
import com.google.firebase.firestore.util.Assert;
2321

2422
/**
@@ -64,17 +62,7 @@ public void applyToRemoteDocument(MutableDocument document, MutationResult mutat
6462

6563
@Override
6664
public FieldMask applyToLocalView(
67-
MutableDocument document, Timestamp localWriteTime, FieldMask mask) {
65+
MutableDocument document, FieldMask previousMask, Timestamp localWriteTime) {
6866
throw Assert.fail("VerifyMutation should only be used in Transactions.");
6967
}
70-
71-
@Nullable
72-
protected ObjectValue getValue() {
73-
return null;
74-
}
75-
76-
@Nullable
77-
protected FieldMask getMask() {
78-
return null;
79-
}
8068
}

0 commit comments

Comments
 (0)