Skip to content

Commit 5e06078

Browse files
Change the order of checks in applyRemoteEvent() (#802)
1 parent 07121a2 commit 5e06078

File tree

1 file changed

+12
-7
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore/local

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,23 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
380380
MaybeDocument doc = entry.getValue();
381381
MaybeDocument existingDoc = existingDocs.get(key);
382382

383-
if (existingDoc == null
383+
// Note: The order of the steps below is important, since we want to ensure that
384+
// rejected limbo resolutions (which fabricate NoDocuments with SnapshotVersion.NONE)
385+
// never add documents to cache.
386+
if (doc instanceof NoDocument && doc.getVersion().equals(SnapshotVersion.NONE)) {
387+
// NoDocuments with SnapshotVersion.NONE are used in manufactured events. We remove
388+
// these documents from cache since we lost access.
389+
remoteDocuments.remove(doc.getKey());
390+
changedDocs.put(key, doc);
391+
} else if (existingDoc == null
384392
|| doc.getVersion().compareTo(existingDoc.getVersion()) > 0
385393
|| (doc.getVersion().compareTo(existingDoc.getVersion()) == 0
386394
&& existingDoc.hasPendingWrites())) {
395+
// TODO(index-free): Comment in this assert when we enable Index-Free queries
396+
// hardAssert(!SnapshotVersion.NONE.equals(remoteEvent.getSnapshotVersion()), "Cannot
397+
// add a document when the remote version is zero");
387398
remoteDocuments.add(doc, remoteEvent.getSnapshotVersion());
388399
changedDocs.put(key, doc);
389-
} else if (doc instanceof NoDocument && doc.getVersion().equals(SnapshotVersion.NONE)) {
390-
// NoDocuments with SnapshotVersion.MIN are used in manufactured events (e.g. in the
391-
// case of a limbo document resolution failing). We remove these documents from cache
392-
// since we lost access.
393-
remoteDocuments.remove(doc.getKey());
394-
changedDocs.put(key, doc);
395400
} else {
396401
Logger.debug(
397402
"LocalStore",

0 commit comments

Comments
 (0)