|
28 | 28 | import com.google.firebase.firestore.model.Document;
|
29 | 29 | import com.google.firebase.firestore.model.DocumentKey;
|
30 | 30 | import com.google.firebase.firestore.model.MaybeDocument;
|
| 31 | +import com.google.firebase.firestore.model.NoDocument; |
31 | 32 | import com.google.firebase.firestore.model.SnapshotVersion;
|
32 | 33 | import com.google.firebase.firestore.model.mutation.Mutation;
|
33 | 34 | import com.google.firebase.firestore.model.mutation.MutationBatch;
|
@@ -389,17 +390,19 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
|
389 | 390 | MaybeDocument doc = entry.getValue();
|
390 | 391 | MaybeDocument existingDoc = existingDocs.get(key);
|
391 | 392 |
|
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). |
397 | 393 | if (existingDoc == null
|
398 |
| - || doc.getVersion().equals(SnapshotVersion.NONE) |
399 | 394 | || (authoritativeUpdates.contains(doc.getKey()) && !existingDoc.hasPendingWrites())
|
400 | 395 | || 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. |
401 | 398 | remoteDocuments.add(doc);
|
402 | 399 | 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); |
403 | 406 | } else {
|
404 | 407 | Logger.debug(
|
405 | 408 | "LocalStore",
|
|
0 commit comments