Skip to content

Commit 910748d

Browse files
committed
Simpler fix
1 parent ea76bd6 commit 910748d

File tree

6 files changed

+9
-34
lines changed

6 files changed

+9
-34
lines changed

firebase-firestore/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Android changes are not released automatically. Ensure that changes are released
22
by opting into a release at
33
[go/firebase-android-release](http:go/firebase-android-release) (Googlers only).
44

5+
# 24.1.0
6+
- [fixed] Fixed missing document fields issue with offline overlays (#3528)
7+
58
# 24.0.2
69
- [fixed] Fixed an issue of long grpc reconnection period, when App moves to
710
foreground after staying in background for a while.

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,6 @@ ImmutableSortedMap<DocumentKey, Document> getLocalViewOfDocuments(
122122
return computeViews(docs, overlays, existenceStateChanged);
123123
}
124124

125-
/**
126-
* Similar to {@link #getDocuments}, but creates the local view from the given {@code baseDocs}
127-
* without retrieving documents from the local store.
128-
*
129-
* @param docs The documents to apply local mutations to get the local views.
130-
*/
131-
ImmutableSortedMap<DocumentKey, Document> getLocalViewOfDocuments(
132-
Map<DocumentKey, MutableDocument> docs) {
133-
Map<DocumentKey, Overlay> overlays = new HashMap<>();
134-
populateOverlays(overlays, docs.keySet());
135-
return computeViews(docs, overlays, new HashSet<>());
136-
}
137-
138125
/*Computes the local view for doc */
139126
private ImmutableSortedMap<DocumentKey, Document> computeViews(
140127
Map<DocumentKey, MutableDocument> docs,

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

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,20 +244,9 @@ public LocalDocumentsResult writeLocally(List<Mutation> mutations) {
244244
return persistence.runTransaction(
245245
"Locally write mutations",
246246
() -> {
247-
// Figure out which keys do not have a remote version in the cache, this is needed to
248-
// create the right overlay mutation: if no remote version presents, we do not need to
249-
// create overlays as patch mutations.
250-
Map<DocumentKey, MutableDocument> remoteDocs = remoteDocuments.getAll(keys);
251-
Set<DocumentKey> docsWithoutRemoteVersion = new HashSet<>();
252-
for (Map.Entry<DocumentKey, MutableDocument> entry : remoteDocs.entrySet()) {
253-
if (!entry.getValue().isValidDocument()) {
254-
docsWithoutRemoteVersion.add(entry.getKey());
255-
}
256-
}
257247
// Load and apply all existing mutations. This lets us compute the current base state for
258248
// all non-idempotent transforms before applying any additional user-provided writes.
259-
ImmutableSortedMap<DocumentKey, Document> documents =
260-
localDocuments.getLocalViewOfDocuments(remoteDocs);
249+
ImmutableSortedMap<DocumentKey, Document> documents = localDocuments.getDocuments(keys);
261250

262251
// For non-idempotent mutations (such as `FieldValue.increment()`), we record the base
263252
// state in a separate patch mutation. This is later used to guarantee consistent values
@@ -281,8 +270,7 @@ public LocalDocumentsResult writeLocally(List<Mutation> mutations) {
281270

282271
MutationBatch batch =
283272
mutationQueue.addMutationBatch(localWriteTime, baseMutations, mutations);
284-
Map<DocumentKey, Mutation> overlays =
285-
batch.applyToLocalDocumentSet(documents, docsWithoutRemoteVersion);
273+
Map<DocumentKey, Mutation> overlays = batch.applyToLocalDocumentSet(documents);
286274
documentOverlayCache.saveOverlays(batch.getBatchId(), overlays);
287275
return new LocalDocumentsResult(batch.getBatchId(), documents);
288276
});

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.firebase.firestore.model.FieldPath;
2424
import com.google.firebase.firestore.model.MutableDocument;
2525
import com.google.firebase.firestore.model.ObjectValue;
26+
import com.google.firebase.firestore.model.SnapshotVersion;
2627
import com.google.firestore.v1.Value;
2728
import java.util.ArrayList;
2829
import java.util.HashMap;
@@ -93,7 +94,7 @@ public static Mutation calculateOverlayMutation(MutableDocument doc, @Nullable F
9394
}
9495

9596
// mask == null when there are Set or Delete being applied to get to the current document.
96-
if (mask == null) {
97+
if (mask == null || doc.getVersion().equals(SnapshotVersion.NONE)) {
9798
if (doc.isNoDocument()) {
9899
return new DeleteMutation(doc.getKey(), Precondition.NONE);
99100
} else {

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ public FieldMask applyToLocalView(MutableDocument document, @Nullable FieldMask
136136
* applications.
137137
*/
138138
public Map<DocumentKey, Mutation> applyToLocalDocumentSet(
139-
ImmutableSortedMap<DocumentKey, Document> documentMap,
140-
Set<DocumentKey> documentsWithoutRemoteVersion) {
139+
ImmutableSortedMap<DocumentKey, Document> documentMap) {
141140
// TODO(mrschmidt): This implementation is O(n^2). If we iterate through the mutations first
142141
// (as done in `applyToLocalView(MutableDocument d)`), we can reduce the complexity to
143142
// O(n).
@@ -147,9 +146,6 @@ public Map<DocumentKey, Mutation> applyToLocalDocumentSet(
147146
// remove this cast.
148147
MutableDocument document = (MutableDocument) documentMap.get(key);
149148
FieldMask mutatedFields = applyToLocalView(document);
150-
// Set mutationFields to null if the document is only from local mutations, this creates
151-
// a Set(or Delete) mutation, instead of trying to create a patch mutation as the overlay.
152-
mutatedFields = documentsWithoutRemoteVersion.contains(key) ? null : mutatedFields;
153149
Mutation overlay = Mutation.calculateOverlayMutation(document, mutatedFields);
154150
overlays.put(key, overlay);
155151
if (!document.isValidDocument()) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public void testHandlesDeleteMutationThenPatchMutationThenAckThenAck() {
759759

760760
acknowledgeMutation(2); // delete mutation
761761
assertRemoved("foo/bar");
762-
assertContains(deletedDoc("foo/bar", 0).setHasLocalMutations());
762+
assertContains(deletedDoc("foo/bar", 2).setHasCommittedMutations());
763763

764764
acknowledgeMutation(3); // patch mutation
765765
assertChanged(unknownDoc("foo/bar", 3));

0 commit comments

Comments
 (0)