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 MemoryMutationQueue method containsKey.
boolean containsKey(DocumentKey key) {
// Create a reference with a zero ID as the start position to find any document reference with
// this key.
DocumentReference reference = new DocumentReference(key, 0);
Iterator<DocumentReference> iterator = batchesByDocumentKey.iteratorFrom(reference);
if (!iterator.hasNext()) {
return false;
}
DocumentKey firstKey = iterator.next().getKey();
return firstKey.equals(key);
}
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 MemoryDocumentOverlayCache method removeOverlaysForBatchId.
@Override
public void removeOverlaysForBatchId(int batchId) {
if (overlayByBatchId.containsKey(batchId)) {
Set<DocumentKey> keys = overlayByBatchId.get(batchId);
overlayByBatchId.remove(batchId);
for (DocumentKey key : keys) {
overlays.remove(key);
}
}
}
use of com.google.firebase.firestore.model.DocumentKey in project firebase-android-sdk by firebase.
the class LocalDocumentsView method getDocumentsMatchingCollectionGroupQuery.
private ImmutableSortedMap<DocumentKey, Document> getDocumentsMatchingCollectionGroupQuery(Query query, IndexOffset offset) {
hardAssert(query.getPath().isEmpty(), "Currently we only support collection group queries at the root.");
String collectionId = query.getCollectionGroup();
ImmutableSortedMap<DocumentKey, Document> results = emptyDocumentMap();
List<ResourcePath> parents = indexManager.getCollectionParents(collectionId);
// aggregate the results.
for (ResourcePath parent : parents) {
Query collectionQuery = query.asCollectionQueryAtPath(parent.append(collectionId));
ImmutableSortedMap<DocumentKey, Document> collectionResults = getDocumentsMatchingCollectionQuery(collectionQuery, offset);
for (Map.Entry<DocumentKey, Document> docEntry : collectionResults) {
results = results.insert(docEntry.getKey(), docEntry.getValue());
}
}
return results;
}
Aggregations