use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class MemoryMutationQueue method getAllMutationBatchesAffectingQuery.
@Override
public List<MutationBatch> getAllMutationBatchesAffectingQuery(Query query) {
hardAssert(!query.isCollectionGroupQuery(), "CollectionGroup queries should be handled in LocalDocumentsView");
// Use the query path as a prefix for testing if a document matches the query.
ResourcePath prefix = query.getPath();
int immediateChildrenPathLength = prefix.length() + 1;
// Construct a document reference for actually scanning the index. Unlike the prefix, the
// document key in this reference must have an even number of segments. The empty segment can be
// used as a suffix of the query path because it precedes all other segments in an ordered
// traversal.
ResourcePath startPath = prefix;
if (!DocumentKey.isDocumentKey(startPath)) {
startPath = startPath.append("");
}
DocumentReference start = new DocumentReference(DocumentKey.fromPath(startPath), 0);
// Find unique batchIDs referenced by all documents potentially matching the query.
ImmutableSortedSet<Integer> uniqueBatchIDs = new ImmutableSortedSet<Integer>(emptyList(), Util.comparator());
Iterator<DocumentReference> iterator = batchesByDocumentKey.iteratorFrom(start);
while (iterator.hasNext()) {
DocumentReference reference = iterator.next();
ResourcePath rowKeyPath = reference.getKey().getPath();
if (!prefix.isPrefixOf(rowKeyPath)) {
break;
}
// TODO: we'll need a different scanner when we implement ancestor queries.
if (rowKeyPath.length() == immediateChildrenPathLength) {
uniqueBatchIDs = uniqueBatchIDs.insert(reference.getId());
}
}
return lookupMutationBatches(uniqueBatchIDs);
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class CountingQueryEngine method wrapRemoteDocumentCache.
private RemoteDocumentCache wrapRemoteDocumentCache(RemoteDocumentCache subject) {
return new RemoteDocumentCache() {
@Override
public void setIndexManager(IndexManager indexManager) {
// Not implemented.
}
@Override
public void add(MutableDocument document, SnapshotVersion readTime) {
subject.add(document, readTime);
}
@Override
public void removeAll(Collection<DocumentKey> keys) {
subject.removeAll(keys);
}
@Override
public MutableDocument get(DocumentKey documentKey) {
MutableDocument result = subject.get(documentKey);
documentsReadByKey[0] += result.isValidDocument() ? 1 : 0;
return result;
}
@Override
public Map<DocumentKey, MutableDocument> getAll(Iterable<DocumentKey> documentKeys) {
Map<DocumentKey, MutableDocument> result = subject.getAll(documentKeys);
for (MutableDocument document : result.values()) {
documentsReadByKey[0] += document.isValidDocument() ? 1 : 0;
}
return result;
}
@Override
public Map<DocumentKey, MutableDocument> getAll(String collectionGroup, IndexOffset offset, int limit) {
Map<DocumentKey, MutableDocument> result = subject.getAll(collectionGroup, offset, limit);
documentsReadByCollection[0] += result.size();
return result;
}
@Override
public Map<DocumentKey, MutableDocument> getAll(ResourcePath collection, IndexOffset offset) {
Map<DocumentKey, MutableDocument> result = subject.getAll(collection, offset);
documentsReadByCollection[0] += result.size();
return result;
}
};
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class IndexManagerTestCase method assertParents.
private void assertParents(IndexManager indexManager, String collectionId, List<String> expected) {
List<ResourcePath> actualPaths = indexManager.getCollectionParents(collectionId);
List<String> actual = new ArrayList<String>();
for (ResourcePath actualPath : actualPaths) {
actual.add(actualPath.toString());
}
expected.sort(String::compareTo);
actual.sort(String::compareTo);
assertEquals(expected, actual);
}
use of com.google.firebase.firestore.model.ResourcePath in project firebase-android-sdk by firebase.
the class QueryTest method testMatchesBasedDocumentKey.
@Test
public void testMatchesBasedDocumentKey() {
ResourcePath queryPath = ResourcePath.fromString("rooms/eros/messages/1");
MutableDocument doc1 = doc("rooms/eros/messages/1", 0, map("text", "msg1"));
MutableDocument doc2 = doc("rooms/eros/messages/2", 0, map("text", "msg2"));
MutableDocument doc3 = doc("rooms/other/messages/1", 0, map("text", "msg3"));
Query query = Query.atPath(queryPath);
assertTrue(query.matches(doc1));
assertFalse(query.matches(doc2));
assertFalse(query.matches(doc3));
}
Aggregations