Skip to content

Commit a96334f

Browse files
Don't persist manufactured documents (#695)
1 parent e58f07c commit a96334f

File tree

1 file changed

+9
-6
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/local

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.firebase.firestore.model.Document;
2929
import com.google.firebase.firestore.model.DocumentKey;
3030
import com.google.firebase.firestore.model.MaybeDocument;
31+
import com.google.firebase.firestore.model.NoDocument;
3132
import com.google.firebase.firestore.model.SnapshotVersion;
3233
import com.google.firebase.firestore.model.mutation.Mutation;
3334
import com.google.firebase.firestore.model.mutation.MutationBatch;
@@ -389,17 +390,19 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
389390
MaybeDocument doc = entry.getValue();
390391
MaybeDocument existingDoc = existingDocs.get(key);
391392

392-
// If a document update isn't authoritative, make sure we don't
393-
// apply an old document version to the remote cache. We make an
394-
// exception for SnapshotVersion.MIN which can happen for
395-
// manufactured events (e.g. in the case of a limbo document
396-
// resolution failing).
397393
if (existingDoc == null
398-
|| doc.getVersion().equals(SnapshotVersion.NONE)
399394
|| (authoritativeUpdates.contains(doc.getKey()) && !existingDoc.hasPendingWrites())
400395
|| doc.getVersion().compareTo(existingDoc.getVersion()) >= 0) {
396+
// If a document update isn't authoritative, make sure we don't apply an old document
397+
// version to the remote cache.
401398
remoteDocuments.add(doc);
402399
changedDocs.put(key, doc);
400+
} else if (doc instanceof NoDocument && doc.getVersion().equals(SnapshotVersion.NONE)) {
401+
// NoDocuments with SnapshotVersion.MIN are used in manufactured events (e.g. in the
402+
// case of a limbo document resolution failing). We remove these documents from cache
403+
// since we lost access.
404+
remoteDocuments.remove(doc.getKey());
405+
changedDocs.put(key, doc);
403406
} else {
404407
Logger.debug(
405408
"LocalStore",

0 commit comments

Comments
 (0)