Skip to content

Commit 4370f77

Browse files
Remove unused baseDoc argument (#2340)
Port from iOS firebase/firebase-ios-sdk#7276
1 parent a2c275c commit 4370f77

File tree

8 files changed

+27
-33
lines changed

8 files changed

+27
-33
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
219219

220220
DocumentKey key = mutation.getKey();
221221
MaybeDocument baseDoc = results.get(key);
222-
MaybeDocument mutatedDoc =
223-
mutation.applyToLocalView(baseDoc, baseDoc, batch.getLocalWriteTime());
222+
MaybeDocument mutatedDoc = mutation.applyToLocalView(baseDoc, batch.getLocalWriteTime());
224223
if (mutatedDoc instanceof Document) {
225224
results = results.insert(key, (Document) mutatedDoc);
226225
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public MaybeDocument applyToRemoteDocument(
7373
@Nullable
7474
@Override
7575
public MaybeDocument applyToLocalView(
76-
@Nullable MaybeDocument maybeDoc, @Nullable MaybeDocument baseDoc, Timestamp localWriteTime) {
76+
@Nullable MaybeDocument maybeDoc, Timestamp localWriteTime) {
7777
verifyKeyMatches(maybeDoc);
7878

7979
if (!this.getPrecondition().isValidFor(maybeDoc)) {

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,14 @@ public abstract MaybeDocument applyToRemoteDocument(
112112
*
113113
* @param maybeDoc The document to mutate. The input document can be null if the client has no
114114
* knowledge of the pre-mutation state of the document.
115-
* @param baseDoc The state of the document prior to this mutation batch. The input document can
116-
* be null if the client has no knowledge of the pre-mutation state of the document.
117115
* @param localWriteTime A timestamp indicating the local write time of the batch this mutation is
118116
* a part of.
119117
* @return The mutated document. The returned document may be null, but only if maybeDoc was null
120118
* and the mutation would not create a new document.
121119
*/
122120
@Nullable
123121
public abstract MaybeDocument applyToLocalView(
124-
@Nullable MaybeDocument maybeDoc, @Nullable MaybeDocument baseDoc, Timestamp localWriteTime);
122+
@Nullable MaybeDocument maybeDoc, Timestamp localWriteTime);
125123

126124
/** Helper for derived classes to implement .equals(). */
127125
boolean hasSameKeyAndPrecondition(Mutation other) {
@@ -164,12 +162,12 @@ static SnapshotVersion getPostMutationVersion(@Nullable MaybeDocument maybeDoc)
164162
* result of applying a transform) for use after a mutation containing transforms has been
165163
* acknowledged by the server.
166164
*
167-
* @param baseDoc The document prior to applying this mutation batch.
165+
* @param maybeDoc The current state of the document after applying all previous mutations.
168166
* @param serverTransformResults The transform results received by the server.
169167
* @return The transform results list.
170168
*/
171169
protected List<Value> serverTransformResults(
172-
@Nullable MaybeDocument baseDoc, List<Value> serverTransformResults) {
170+
@Nullable MaybeDocument maybeDoc, List<Value> serverTransformResults) {
173171
ArrayList<Value> transformResults = new ArrayList<>(fieldTransforms.size());
174172
hardAssert(
175173
fieldTransforms.size() == serverTransformResults.size(),
@@ -182,8 +180,8 @@ protected List<Value> serverTransformResults(
182180
TransformOperation transform = fieldTransform.getOperation();
183181

184182
Value previousValue = null;
185-
if (baseDoc instanceof Document) {
186-
previousValue = ((Document) baseDoc).getField(fieldTransform.getFieldPath());
183+
if (maybeDoc instanceof Document) {
184+
previousValue = ((Document) maybeDoc).getField(fieldTransform.getFieldPath());
187185
}
188186

189187
transformResults.add(
@@ -198,11 +196,10 @@ protected List<Value> serverTransformResults(
198196
*
199197
* @param localWriteTime The local time of the mutation (used to generate ServerTimestampValues).
200198
* @param maybeDoc The current state of the document after applying all previous mutations.
201-
* @param baseDoc The document prior to applying this mutation batch.
202199
* @return The transform results list.
203200
*/
204201
protected List<Value> localTransformResults(
205-
Timestamp localWriteTime, @Nullable MaybeDocument maybeDoc, @Nullable MaybeDocument baseDoc) {
202+
Timestamp localWriteTime, @Nullable MaybeDocument maybeDoc) {
206203
ArrayList<Value> transformResults = new ArrayList<>(fieldTransforms.size());
207204
for (FieldTransform fieldTransform : fieldTransforms) {
208205
TransformOperation transform = fieldTransform.getOperation();

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,15 @@ public MaybeDocument applyToLocalView(DocumentKey documentKey, @Nullable MaybeDo
124124
for (int i = 0; i < baseMutations.size(); i++) {
125125
Mutation mutation = baseMutations.get(i);
126126
if (mutation.getKey().equals(documentKey)) {
127-
maybeDoc = mutation.applyToLocalView(maybeDoc, maybeDoc, localWriteTime);
127+
maybeDoc = mutation.applyToLocalView(maybeDoc, localWriteTime);
128128
}
129129
}
130130

131-
MaybeDocument baseDoc = maybeDoc;
132-
133131
// Second, apply all user-provided mutations.
134132
for (int i = 0; i < mutations.size(); i++) {
135133
Mutation mutation = mutations.get(i);
136134
if (mutation.getKey().equals(documentKey)) {
137-
maybeDoc = mutation.applyToLocalView(maybeDoc, baseDoc, localWriteTime);
135+
maybeDoc = mutation.applyToLocalView(maybeDoc, localWriteTime);
138136
}
139137
}
140138
return maybeDoc;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ public MaybeDocument applyToRemoteDocument(
130130
@Nullable
131131
@Override
132132
public MaybeDocument applyToLocalView(
133-
@Nullable MaybeDocument maybeDoc, @Nullable MaybeDocument baseDoc, Timestamp localWriteTime) {
133+
@Nullable MaybeDocument maybeDoc, Timestamp localWriteTime) {
134134
verifyKeyMatches(maybeDoc);
135135

136136
if (!getPrecondition().isValidFor(maybeDoc)) {
137137
return maybeDoc;
138138
}
139139

140-
List<Value> transformResults = localTransformResults(localWriteTime, maybeDoc, baseDoc);
140+
List<Value> transformResults = localTransformResults(localWriteTime, maybeDoc);
141141
SnapshotVersion version = getPostMutationVersion(maybeDoc);
142142
ObjectValue newData = patchDocument(maybeDoc, transformResults);
143143
return new Document(getKey(), version, newData, Document.DocumentState.LOCAL_MUTATIONS);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ public MaybeDocument applyToRemoteDocument(
9494
@Nullable
9595
@Override
9696
public MaybeDocument applyToLocalView(
97-
@Nullable MaybeDocument maybeDoc, @Nullable MaybeDocument baseDoc, Timestamp localWriteTime) {
97+
@Nullable MaybeDocument maybeDoc, Timestamp localWriteTime) {
9898
verifyKeyMatches(maybeDoc);
9999

100100
if (!this.getPrecondition().isValidFor(maybeDoc)) {
101101
return maybeDoc;
102102
}
103103

104-
List<Value> transformResults = localTransformResults(localWriteTime, maybeDoc, baseDoc);
104+
List<Value> transformResults = localTransformResults(localWriteTime, maybeDoc);
105105
ObjectValue newData = transformObject(value, transformResults);
106106

107107
SnapshotVersion version = getPostMutationVersion(maybeDoc);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public MaybeDocument applyToRemoteDocument(
6565
@Nullable
6666
@Override
6767
public MaybeDocument applyToLocalView(
68-
@Nullable MaybeDocument maybeDoc, @Nullable MaybeDocument baseDoc, Timestamp localWriteTime) {
68+
@Nullable MaybeDocument maybeDoc, Timestamp localWriteTime) {
6969
throw Assert.fail("VerifyMutation should only be used in Transactions.");
7070
}
7171
}

firebase-firestore/src/test/java/com/google/firebase/firestore/model/MutationTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void testAppliesSetsToDocuments() {
6363
Document baseDoc = doc("collection/key", 0, data);
6464

6565
Mutation set = setMutation("collection/key", map("bar", "bar-value"));
66-
MaybeDocument setDoc = set.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
66+
MaybeDocument setDoc = set.applyToLocalView(baseDoc, Timestamp.now());
6767
assertEquals(
6868
doc("collection/key", 0, map("bar", "bar-value"), Document.DocumentState.LOCAL_MUTATIONS),
6969
setDoc);
@@ -75,7 +75,7 @@ public void testAppliesPatchToDocuments() {
7575
Document baseDoc = doc("collection/key", 0, data);
7676

7777
Mutation patch = patchMutation("collection/key", map("foo.bar", "new-bar-value"));
78-
MaybeDocument local = patch.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
78+
MaybeDocument local = patch.applyToLocalView(baseDoc, Timestamp.now());
7979
Map<String, Object> expectedData = map("foo", map("bar", "new-bar-value"), "baz", "baz-value");
8080
assertEquals(
8181
doc("collection/key", 0, expectedData, Document.DocumentState.LOCAL_MUTATIONS), local);
@@ -87,7 +87,7 @@ public void testAppliesPatchWithMergeToDocuments() {
8787
Mutation upsert =
8888
mergeMutation(
8989
"collection/key", map("foo.bar", "new-bar-value"), Arrays.asList(field("foo.bar")));
90-
MaybeDocument newDoc = upsert.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
90+
MaybeDocument newDoc = upsert.applyToLocalView(baseDoc, Timestamp.now());
9191
Map<String, Object> expectedData = map("foo", map("bar", "new-bar-value"));
9292
assertEquals(
9393
doc("collection/key", 0, expectedData, Document.DocumentState.LOCAL_MUTATIONS), newDoc);
@@ -99,7 +99,7 @@ public void testAppliesPatchToNullDocWithMergeToDocuments() {
9999
Mutation upsert =
100100
mergeMutation(
101101
"collection/key", map("foo.bar", "new-bar-value"), Arrays.asList(field("foo.bar")));
102-
MaybeDocument newDoc = upsert.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
102+
MaybeDocument newDoc = upsert.applyToLocalView(baseDoc, Timestamp.now());
103103
Map<String, Object> expectedData = map("foo", map("bar", "new-bar-value"));
104104
assertEquals(
105105
doc("collection/key", 0, expectedData, Document.DocumentState.LOCAL_MUTATIONS), newDoc);
@@ -114,7 +114,7 @@ public void testDeletesValuesFromTheFieldMask() {
114114
FieldMask mask = fieldMask("foo.bar");
115115
Mutation patch = new PatchMutation(key, ObjectValue.emptyObject(), mask, Precondition.NONE);
116116

117-
MaybeDocument patchDoc = patch.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
117+
MaybeDocument patchDoc = patch.applyToLocalView(baseDoc, Timestamp.now());
118118
Map<String, Object> expectedData = map("foo", map("baz", "baz-value"));
119119
assertEquals(
120120
doc("collection/key", 0, expectedData, Document.DocumentState.LOCAL_MUTATIONS), patchDoc);
@@ -126,7 +126,7 @@ public void testPatchesPrimitiveValue() {
126126
Document baseDoc = doc("collection/key", 0, data);
127127

128128
Mutation patch = patchMutation("collection/key", map("foo.bar", "new-bar-value"));
129-
MaybeDocument patchedDoc = patch.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
129+
MaybeDocument patchedDoc = patch.applyToLocalView(baseDoc, Timestamp.now());
130130
Map<String, Object> expectedData = map("foo", map("bar", "new-bar-value"), "baz", "baz-value");
131131
assertEquals(
132132
doc("collection/key", 0, expectedData, Document.DocumentState.LOCAL_MUTATIONS), patchedDoc);
@@ -136,7 +136,7 @@ public void testPatchesPrimitiveValue() {
136136
public void testPatchingDeletedDocumentsDoesNothing() {
137137
MaybeDocument baseDoc = deletedDoc("collection/key", 0);
138138
Mutation patch = patchMutation("collection/key", map("foo", "bar"));
139-
MaybeDocument patchedDoc = patch.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
139+
MaybeDocument patchedDoc = patch.applyToLocalView(baseDoc, Timestamp.now());
140140
assertEquals(baseDoc, patchedDoc);
141141
}
142142

@@ -148,7 +148,7 @@ public void testAppliesLocalServerTimestampTransformsToDocuments() {
148148
Timestamp timestamp = Timestamp.now();
149149
Mutation transform =
150150
patchMutation("collection/key", map("foo.bar", FieldValue.serverTimestamp()));
151-
MaybeDocument transformedDoc = transform.applyToLocalView(baseDoc, baseDoc, timestamp);
151+
MaybeDocument transformedDoc = transform.applyToLocalView(baseDoc, timestamp);
152152

153153
// Server timestamps aren't parsed, so we manually insert it.
154154
ObjectValue expectedData =
@@ -462,7 +462,7 @@ private void verifyTransform(
462462

463463
for (Map<String, Object> transformData : transforms) {
464464
PatchMutation transform = patchMutation("collection/key", transformData);
465-
currentDoc = transform.applyToLocalView(currentDoc, currentDoc, Timestamp.now());
465+
currentDoc = transform.applyToLocalView(currentDoc, Timestamp.now());
466466
}
467467

468468
Document expectedDoc =
@@ -544,7 +544,7 @@ public void testDeleteDeletes() {
544544
Document baseDoc = doc("collection/key", 0, data);
545545

546546
Mutation delete = deleteMutation("collection/key");
547-
MaybeDocument deletedDoc = delete.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
547+
MaybeDocument deletedDoc = delete.applyToLocalView(baseDoc, Timestamp.now());
548548
assertEquals(deletedDoc("collection/key", 0), deletedDoc);
549549
}
550550

@@ -691,8 +691,8 @@ public void testIncrementTwice() {
691691
Map<String, Object> increment = map("sum", FieldValue.increment(1));
692692
Mutation mutation = patchMutation("collection/key", increment);
693693

694-
MaybeDocument mutatedDoc = mutation.applyToLocalView(baseDoc, baseDoc, Timestamp.now());
695-
mutatedDoc = mutation.applyToLocalView(mutatedDoc, baseDoc, Timestamp.now());
694+
MaybeDocument mutatedDoc = mutation.applyToLocalView(baseDoc, Timestamp.now());
695+
mutatedDoc = mutation.applyToLocalView(mutatedDoc, Timestamp.now());
696696

697697
assertEquals(wrap(2L), ((Document) mutatedDoc).getField(field("sum")));
698698
}

0 commit comments

Comments
 (0)