use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class RemoteDocumentCacheTestCase method testGetAllFromUsesReadTimeNotUpdateTime.
@Test
public void testGetAllFromUsesReadTimeNotUpdateTime() {
addTestDocumentAtPath("b/old", /* updateTime= */
1, /* readTime= */
2);
addTestDocumentAtPath("b/new", /* updateTime= */
2, /* readTime= */
1);
ResourcePath collection = path("b");
Map<DocumentKey, MutableDocument> results = remoteDocumentCache.getAll(collection, IndexOffset.createSuccessor(version(1), -1));
assertThat(results.values()).containsExactly(doc("b/old", 1, DOC_DATA));
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class RemoteSerializer method decodeMissingDocument.
private MutableDocument decodeMissingDocument(BatchGetDocumentsResponse response) {
Assert.hardAssert(response.getResultCase().equals(ResultCase.MISSING), "Tried to deserialize a missing document from a found document.");
DocumentKey key = decodeKey(response.getMissing());
SnapshotVersion version = decodeVersion(response.getReadTime());
hardAssert(!version.equals(SnapshotVersion.NONE), "Got a no document response with no snapshot version");
return MutableDocument.newNoDocument(key, version);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class TargetState method toTargetChange.
/**
* Creates a target change from the current set of changes.
*
* <p>To reset the document changes after raising this snapshot, call `clearChanges()`.
*/
TargetChange toTargetChange() {
ImmutableSortedSet<DocumentKey> addedDocuments = DocumentKey.emptyKeySet();
ImmutableSortedSet<DocumentKey> modifiedDocuments = DocumentKey.emptyKeySet();
ImmutableSortedSet<DocumentKey> removedDocuments = DocumentKey.emptyKeySet();
for (Map.Entry<DocumentKey, DocumentViewChange.Type> entry : this.documentChanges.entrySet()) {
DocumentKey key = entry.getKey();
DocumentViewChange.Type changeType = entry.getValue();
switch(changeType) {
case ADDED:
addedDocuments = addedDocuments.insert(key);
break;
case MODIFIED:
modifiedDocuments = modifiedDocuments.insert(key);
break;
case REMOVED:
removedDocuments = removedDocuments.insert(key);
break;
default:
throw fail("Encountered invalid change type: %s", changeType);
}
}
return new TargetChange(resumeToken, current, addedDocuments, modifiedDocuments, removedDocuments);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class WatchChangeAggregator method handleExistenceFilter.
/**
* Handles existence filters and synthesizes deletes for filter mismatches. Targets that are
* invalidated by filter mismatches are added to `pendingTargetResets`.
*/
public void handleExistenceFilter(ExistenceFilterWatchChange watchChange) {
int targetId = watchChange.getTargetId();
int expectedCount = watchChange.getExistenceFilter().getCount();
TargetData targetData = queryDataForActiveTarget(targetId);
if (targetData != null) {
Target target = targetData.getTarget();
if (target.isDocumentQuery()) {
if (expectedCount == 0) {
// The existence filter told us the document does not exist. We deduce that this document
// does not exist and apply a deleted document to our updates. Without applying this
// deleted document there might be another query that will raise this document as part of
// a snapshot until it is resolved, essentially exposing inconsistency between queries.
DocumentKey key = DocumentKey.fromPath(target.getPath());
MutableDocument result = MutableDocument.newNoDocument(key, SnapshotVersion.NONE);
removeDocumentFromTarget(targetId, key, result);
} else {
hardAssert(expectedCount == 1, "Single document existence filter with count: %d", expectedCount);
}
} else {
long currentSize = getCurrentDocumentCountForTarget(targetId);
if (currentSize != expectedCount) {
// Existence filter mismatch: We reset the mapping and raise a new snapshot with
// `isFromCache:true`.
resetTarget(targetId);
pendingTargetResets.add(targetId);
}
}
}
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class WatchChangeAggregator method handleDocumentChange.
/**
* Processes and adds the DocumentWatchChange to the current set of changes.
*/
public void handleDocumentChange(DocumentChange documentChange) {
MutableDocument document = documentChange.getNewDocument();
DocumentKey documentKey = documentChange.getDocumentKey();
for (int targetId : documentChange.getUpdatedTargetIds()) {
if (document != null && document.isFoundDocument()) {
addDocumentToTarget(targetId, document);
} else {
removeDocumentFromTarget(targetId, documentKey, document);
}
}
for (int targetId : documentChange.getRemovedTargetIds()) {
removeDocumentFromTarget(targetId, documentKey, documentChange.getNewDocument());
}
}
Aggregations