Skip to content

Don't persist manufactured documents #695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.firebase.firestore.model.Document;
import com.google.firebase.firestore.model.DocumentKey;
import com.google.firebase.firestore.model.MaybeDocument;
import com.google.firebase.firestore.model.NoDocument;
import com.google.firebase.firestore.model.SnapshotVersion;
import com.google.firebase.firestore.model.mutation.Mutation;
import com.google.firebase.firestore.model.mutation.MutationBatch;
Expand Down Expand Up @@ -381,17 +382,19 @@ public ImmutableSortedMap<DocumentKey, MaybeDocument> applyRemoteEvent(RemoteEve
MaybeDocument doc = entry.getValue();
MaybeDocument existingDoc = existingDocs.get(key);

// If a document update isn't authoritative, make sure we don't
// apply an old document version to the remote cache. We make an
// exception for SnapshotVersion.MIN which can happen for
// manufactured events (e.g. in the case of a limbo document
// resolution failing).
if (existingDoc == null
|| doc.getVersion().equals(SnapshotVersion.NONE)
|| (authoritativeUpdates.contains(doc.getKey()) && !existingDoc.hasPendingWrites())
|| doc.getVersion().compareTo(existingDoc.getVersion()) >= 0) {
// If a document update isn't authoritative, make sure we don't apply an old document
// version to the remote cache.
remoteDocuments.add(doc);
changedDocs.put(key, doc);
} else if (doc instanceof NoDocument && doc.getVersion().equals(SnapshotVersion.NONE)) {
// NoDocuments with SnapshotVersion.MIN are used in manufactured events (e.g. in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure make the comment look as if it applies to the block about authoritative updates. Better to put this in the next block (and pull the comment above into this one--above the actions taken).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// case of a limbo document resolution failing). We remove these documents from cache
// since we lost access.
remoteDocuments.remove(doc.getKey());
changedDocs.put(key, doc);
} else {
Logger.debug(
"LocalStore",
Expand Down