use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class MemoryRemoteDocumentCache method removeAll.
@Override
public void removeAll(Collection<DocumentKey> keys) {
hardAssert(indexManager != null, "setIndexManager() not called");
ImmutableSortedMap<DocumentKey, Document> deletedDocs = emptyDocumentMap();
for (DocumentKey key : keys) {
docs = docs.remove(key);
deletedDocs = deletedDocs.insert(key, MutableDocument.newNoDocument(key, SnapshotVersion.NONE));
}
indexManager.updateIndexEntries(deletedDocs);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class MemoryRemoteDocumentCache method getAll.
@Override
public Map<DocumentKey, MutableDocument> getAll(ResourcePath collection, IndexOffset offset) {
Map<DocumentKey, MutableDocument> result = new HashMap<>();
// Documents are ordered by key, so we can use a prefix scan to narrow down the documents
// we need to match the query against.
DocumentKey prefix = DocumentKey.fromPath(collection.append(""));
Iterator<Map.Entry<DocumentKey, Document>> iterator = docs.iteratorFrom(prefix);
while (iterator.hasNext()) {
Map.Entry<DocumentKey, Document> entry = iterator.next();
Document doc = entry.getValue();
DocumentKey key = entry.getKey();
if (!collection.isPrefixOf(key.getPath())) {
// We are now scanning the next collection. Abort.
break;
}
if (key.getPath().length() > collection.length() + 1) {
// Exclude entries from subcollections.
continue;
}
if (IndexOffset.fromDocument(doc).compareTo(offset) <= 0) {
// The document sorts before the offset.
continue;
}
result.put(doc.getKey(), doc.mutableCopy());
}
return result;
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class MemoryTargetCache method removeMatchingKeys.
@Override
public void removeMatchingKeys(ImmutableSortedSet<DocumentKey> keys, int targetId) {
references.removeReferences(keys, targetId);
ReferenceDelegate referenceDelegate = persistence.getReferenceDelegate();
for (DocumentKey key : keys) {
referenceDelegate.removeReference(key);
}
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class QueryEngine method performQueryUsingIndex.
/**
* Performs an indexed query that evaluates the query based on a collection's persisted index
* values. Returns {@code null} if an index is not available.
*/
@Nullable
private ImmutableSortedMap<DocumentKey, Document> performQueryUsingIndex(Query query) {
if (query.matchesAllDocuments()) {
// Don't use indexes for queries that can be executed by scanning the collection.
return null;
}
Target target = query.toTarget();
IndexType indexType = indexManager.getIndexType(target);
if (indexType.equals(IndexType.NONE)) {
// The target cannot be served from any index.
return null;
}
if (query.hasLimit() && indexType.equals(IndexType.PARTIAL)) {
// in such cases.
return performQueryUsingIndex(query.limitToFirst(Target.NO_LIMIT));
}
List<DocumentKey> keys = indexManager.getDocumentsMatchingTarget(target);
hardAssert(keys != null, "index manager must return results for partial and full indexes.");
ImmutableSortedMap<DocumentKey, Document> indexedDocuments = localDocumentsView.getDocuments(keys);
IndexOffset offset = indexManager.getMinOffset(target);
ImmutableSortedSet<Document> previousResults = applyQuery(query, indexedDocuments);
if (needsRefill(query, keys.size(), previousResults, offset.getReadTime())) {
// incorporated.
return performQueryUsingIndex(query.limitToFirst(Target.NO_LIMIT));
}
return appendRemainingResults(previousResults, query, offset);
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class ReferenceSet method containsKey.
public boolean containsKey(DocumentKey key) {
DocumentReference ref = new DocumentReference(key, 0);
Iterator<DocumentReference> iterator = referencesByKey.iteratorFrom(ref);
if (!iterator.hasNext()) {
return false;
}
DocumentKey firstKey = iterator.next().getKey();
return firstKey.equals(key);
}
Aggregations