From 1c40e7aada6b32bbc621f06fb5f380149606a58d Mon Sep 17 00:00:00 2001 From: zxu Date: Mon, 5 Mar 2018 11:30:59 -0500 Subject: add converters and port paths to FSTQuery (#869) * add converters and fix FSTQuery.{h,m} only * address changes * a change forget to address * add a dummy function to make inline-only-library buildable --- Firestore/Source/Local/FSTLevelDBMutationQueue.mm | 2 +- Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm | 5 +++-- Firestore/Source/Local/FSTLocalDocumentsView.mm | 6 ++++-- Firestore/Source/Local/FSTMemoryMutationQueue.mm | 4 ++-- Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm | 5 +++-- 5 files changed, 13 insertions(+), 9 deletions(-) (limited to 'Firestore/Source/Local') diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index 248ef9a..9041ddc 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -426,7 +426,7 @@ static ReadOptions StandardReadOptions() { FSTAssert(![query isDocumentQuery], @"Document queries shouldn't go down this path"); NSString *userID = self.userID; - FSTResourcePath *queryPath = query.path; + FSTResourcePath *queryPath = [FSTResourcePath resourcePathWithCPPResourcePath:query.path]; int immediateChildrenPathLength = queryPath.length + 1; // TODO(mcg): Actually implement a single-collection query diff --git a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm index b842cb5..17ecb53 100644 --- a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm @@ -104,7 +104,8 @@ static ReadOptions StandardReadOptions() { // Documents are ordered by key, so we can use a prefix scan to narrow down // the documents we need to match the query against. - std::string startKey = [FSTLevelDBRemoteDocumentKey keyPrefixWithResourcePath:query.path]; + std::string startKey = [FSTLevelDBRemoteDocumentKey + keyPrefixWithResourcePath:[FSTResourcePath resourcePathWithCPPResourcePath:query.path]]; std::unique_ptr it(_db->NewIterator(StandardReadOptions())); it->Seek(startKey); @@ -112,7 +113,7 @@ static ReadOptions StandardReadOptions() { for (; it->Valid() && [currentKey decodeKey:it->key()]; it->Next()) { FSTMaybeDocument *maybeDoc = [self decodedMaybeDocument:it->value() withKey:currentKey.documentKey]; - if (![query.path isPrefixOfPath:maybeDoc.key.path]) { + if (!query.path.IsPrefixOf([maybeDoc.key.path toCPPResourcePath])) { break; } else if ([maybeDoc isKindOfClass:[FSTDocument class]]) { results = [results dictionaryBySettingObject:(FSTDocument *)maybeDoc forKey:maybeDoc.key]; diff --git a/Firestore/Source/Local/FSTLocalDocumentsView.mm b/Firestore/Source/Local/FSTLocalDocumentsView.mm index 0e88958..4bcdf47 100644 --- a/Firestore/Source/Local/FSTLocalDocumentsView.mm +++ b/Firestore/Source/Local/FSTLocalDocumentsView.mm @@ -25,6 +25,7 @@ #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" +#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Util/FSTAssert.h" NS_ASSUME_NONNULL_BEGIN @@ -74,8 +75,9 @@ NS_ASSUME_NONNULL_BEGIN } - (FSTDocumentDictionary *)documentsMatchingQuery:(FSTQuery *)query { - if ([FSTDocumentKey isDocumentKey:query.path]) { - return [self documentsMatchingDocumentQuery:query.path]; + if ([FSTDocumentKey isDocumentKey:[FSTResourcePath resourcePathWithCPPResourcePath:query.path]]) { + return [self documentsMatchingDocumentQuery:[FSTResourcePath + resourcePathWithCPPResourcePath:query.path]]; } else { return [self documentsMatchingCollectionQuery:query]; } diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.mm b/Firestore/Source/Local/FSTMemoryMutationQueue.mm index 2a6a1cc..bf4f600 100644 --- a/Firestore/Source/Local/FSTMemoryMutationQueue.mm +++ b/Firestore/Source/Local/FSTMemoryMutationQueue.mm @@ -248,13 +248,13 @@ static const NSComparator NumberComparator = ^NSComparisonResult(NSNumber *left, - (NSArray *)allMutationBatchesAffectingQuery:(FSTQuery *)query { // Use the query path as a prefix for testing if a document matches the query. - FSTResourcePath *prefix = query.path; + FSTResourcePath *prefix = [FSTResourcePath resourcePathWithCPPResourcePath:query.path]; 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. - FSTResourcePath *startPath = query.path; + FSTResourcePath *startPath = [FSTResourcePath resourcePathWithCPPResourcePath:query.path]; if (![FSTDocumentKey isDocumentKey:startPath]) { startPath = [startPath pathByAppendingSegment:@""]; } diff --git a/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm b/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm index 9bbc047..7d5e1e2 100644 --- a/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm @@ -60,10 +60,11 @@ NS_ASSUME_NONNULL_BEGIN // Documents are ordered by key, so we can use a prefix scan to narrow down the documents // we need to match the query against. - FSTDocumentKey *prefix = [FSTDocumentKey keyWithPath:[query.path pathByAppendingSegment:@""]]; + FSTDocumentKey *prefix = [FSTDocumentKey + keyWithPath:[FSTResourcePath resourcePathWithCPPResourcePath:query.path.Append("")]]; NSEnumerator *enumerator = [self.docs keyEnumeratorFrom:prefix]; for (FSTDocumentKey *key in enumerator) { - if (![query.path isPrefixOfPath:key.path]) { + if (!query.path.IsPrefixOf([key.path toCPPResourcePath])) { break; } FSTMaybeDocument *maybeDoc = self.docs[key]; -- cgit v1.2.3