Skip to content

Commit 8394f24

Browse files
authored
Backport some changes for overlays (#3691)
* Backport some changes for overlays * Format
1 parent 889bf9a commit 8394f24

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Document getDocument(DocumentKey key) {
9191
Overlay overlay = documentOverlayCache.getOverlay(key);
9292
MutableDocument document = getBaseDocument(key, overlay);
9393
if (overlay != null) {
94-
overlay.getMutation().applyToLocalView(document, null, Timestamp.now());
94+
overlay.getMutation().applyToLocalView(document, FieldMask.EMPTY, Timestamp.now());
9595
}
9696
return document;
9797
}
@@ -171,7 +171,9 @@ private Map<DocumentKey, OverlayedDocument> computeViews(
171171
recalculateDocuments.put(doc.getKey(), doc);
172172
} else if (overlay != null) {
173173
mutatedFields.put(doc.getKey(), overlay.getMutation().getFieldMask());
174-
overlay.getMutation().applyToLocalView(doc, null, Timestamp.now());
174+
overlay
175+
.getMutation()
176+
.applyToLocalView(doc, overlay.getMutation().getFieldMask(), Timestamp.now());
175177
}
176178
}
177179

@@ -375,7 +377,9 @@ private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollection
375377
for (Map.Entry<DocumentKey, MutableDocument> docEntry : remoteDocuments.entrySet()) {
376378
Overlay overlay = overlays.get(docEntry.getKey());
377379
if (overlay != null) {
378-
overlay.getMutation().applyToLocalView(docEntry.getValue(), null, Timestamp.now());
380+
overlay
381+
.getMutation()
382+
.applyToLocalView(docEntry.getValue(), FieldMask.EMPTY, Timestamp.now());
379383
}
380384
// Finally, insert the documents that still match the query
381385
if (query.matches(docEntry.getValue())) {

firebase-firestore/src/test/java/com/google/firebase/firestore/local/LocalStoreTestCase.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,16 +1337,17 @@ public void testHoldsBackTransforms() {
13371337
emptyList()));
13381338
assertChanged(doc("foo/bar", 1, map("sum", 0, "array_union", new ArrayList<>())));
13391339

1340-
writeMutations(
1341-
asList(
1342-
patchMutation("foo/bar", map("sum", FieldValue.increment(1))),
1343-
patchMutation("foo/bar", map("array_union", FieldValue.arrayUnion("foo")))));
1340+
writeMutation(patchMutation("foo/bar", map("sum", FieldValue.increment(1))));
1341+
assertChanged(
1342+
doc("foo/bar", 1, map("sum", 1, "array_union", new ArrayList<>())).setHasLocalMutations());
1343+
1344+
writeMutation(patchMutation("foo/bar", map("array_union", FieldValue.arrayUnion("foo"))));
13441345
assertChanged(
13451346
doc("foo/bar", 1, map("sum", 1, "array_union", Collections.singletonList("foo")))
13461347
.setHasLocalMutations());
13471348

1348-
// The sum transform is not idempotent and the backend's updated value is ignored. The
1349-
// ArrayUnion transform is recomputed and includes the backend value.
1349+
// The sum transform and array union transform make the SDK ignore the
1350+
// backend's updated value.
13501351
applyRemoteEvent(
13511352
addedRemoteEvent(
13521353
doc("foo/bar", 2, map("sum", 1337, "array_union", Collections.singletonList("bar"))),
@@ -1355,10 +1356,18 @@ public void testHoldsBackTransforms() {
13551356
assertChanged(
13561357
doc("foo/bar", 2, map("sum", 1, "array_union", asList("foo"))).setHasLocalMutations());
13571358

1358-
acknowledgeMutationWithTransformResults(3, 1338, asList("bar", "foo"));
1359+
// With a field transform acknowledgement, the overlay is recalculated with
1360+
// remaining local mutations.
1361+
acknowledgeMutationWithTransformResults(3, 1338);
13591362
assertChanged(
13601363
doc("foo/bar", 3, map("sum", 1338, "array_union", asList("bar", "foo")))
13611364
.setReadTime(new SnapshotVersion(new Timestamp(0, 3000)))
1365+
.setHasLocalMutations());
1366+
1367+
acknowledgeMutationWithTransformResults(4, asList("bar", "foo"));
1368+
assertChanged(
1369+
doc("foo/bar", 4, map("sum", 1338, "array_union", asList("bar", "foo")))
1370+
.setReadTime(new SnapshotVersion(new Timestamp(0, 4000)))
13621371
.setHasCommittedMutations());
13631372
}
13641373

0 commit comments

Comments
 (0)