diff options
Diffstat (limited to 'Firestore/Source/Local')
-rw-r--r-- | Firestore/Source/Local/FSTLevelDB.mm | 3 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBKey.h | 21 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBKey.mm | 26 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBMutationQueue.mm | 17 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBQueryCache.mm | 4 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm | 4 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTLocalDocumentsView.mm | 13 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTMemoryMutationQueue.mm | 1 | ||||
-rw-r--r-- | Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm | 1 |
9 files changed, 45 insertions, 45 deletions
diff --git a/Firestore/Source/Local/FSTLevelDB.mm b/Firestore/Source/Local/FSTLevelDB.mm index 9d3c35e..ac29304 100644 --- a/Firestore/Source/Local/FSTLevelDB.mm +++ b/Firestore/Source/Local/FSTLevelDB.mm @@ -113,8 +113,7 @@ using leveldb::WriteOptions; NSString *segment = util::WrapNSStringNoCopy(databaseInfo.database_id().project_id()); if (!databaseInfo.database_id().IsDefaultDatabase()) { segment = [NSString - stringWithFormat:@"%@.%@", segment, - util::WrapNSStringNoCopy(databaseInfo.database_id().database_id())]; + stringWithFormat:@"%@.%s", segment, databaseInfo.database_id().database_id().c_str()]; } directory = [directory stringByAppendingPathComponent:segment]; diff --git a/Firestore/Source/Local/FSTLevelDBKey.h b/Firestore/Source/Local/FSTLevelDBKey.h index f3f4bcf..c7a64ee 100644 --- a/Firestore/Source/Local/FSTLevelDBKey.h +++ b/Firestore/Source/Local/FSTLevelDBKey.h @@ -19,8 +19,9 @@ #import "Firestore/Source/Core/FSTTypes.h" #import "Firestore/Source/Local/StringView.h" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" + @class FSTDocumentKey; -@class FSTResourcePath; NS_ASSUME_NONNULL_BEGIN @@ -34,7 +35,7 @@ NS_ASSUME_NONNULL_BEGIN // document_mutations: // - tableName: string = "document_mutation" // - userID: string -// - path: FSTResourcePath +// - path: ResourcePath // - batchID: FSTBatchID // // mutation_queues: @@ -56,16 +57,16 @@ NS_ASSUME_NONNULL_BEGIN // target_documents: // - tableName: string = "target_document" // - targetID: FSTTargetID -// - path: FSTResourcePath +// - path: ResourcePath // // document_targets: // - tableName: string = "document_target" -// - path: FSTResourcePath +// - path: ResourcePath // - targetID: FSTTargetID // // remote_documents: // - tableName: string = "remote_document" -// - path: FSTResourcePath +// - path: ResourcePath /** Helpers for any LevelDB key. */ @interface FSTLevelDBKey : NSObject @@ -128,12 +129,12 @@ NS_ASSUME_NONNULL_BEGIN /** * Creates a key prefix that points just before the first key for the userID and resource path. * - * Note that this uses an FSTResourcePath rather than an FSTDocumentKey in order to allow prefix + * Note that this uses a ResourcePath rather than an FSTDocumentKey in order to allow prefix * scans over a collection. However a naive scan over those results isn't useful since it would * match both immediate children of the collection and any subcollections. */ + (std::string)keyPrefixWithUserID:(Firestore::StringView)userID - resourcePath:(FSTResourcePath *)resourcePath; + resourcePath:(const firebase::firestore::model::ResourcePath &)resourcePath; /** Creates a complete key that points to a specific userID, document key, and batchID. */ + (std::string)keyWithUserID:(Firestore::StringView)userID @@ -291,7 +292,8 @@ NS_ASSUME_NONNULL_BEGIN + (std::string)keyPrefix; /** Creates a key that points to the first document-target association for document. */ -+ (std::string)keyPrefixWithResourcePath:(FSTResourcePath *)resourcePath; ++ (std::string)keyPrefixWithResourcePath: + (const firebase::firestore::model::ResourcePath &)resourcePath; /** Creates a key that points to a specific document-target entry. */ + (std::string)keyWithDocumentKey:(FSTDocumentKey *)documentKey targetID:(FSTTargetID)targetID; @@ -328,7 +330,8 @@ NS_ASSUME_NONNULL_BEGIN * a document key prefix will match the document itself and any documents that exist in its * subcollections. */ -+ (std::string)keyPrefixWithResourcePath:(FSTResourcePath *)resourcePath; ++ (std::string)keyPrefixWithResourcePath: + (const firebase::firestore::model::ResourcePath &)resourcePath; /** * Decodes the contents of a remote document key into properties on this instance. This can only diff --git a/Firestore/Source/Local/FSTLevelDBKey.mm b/Firestore/Source/Local/FSTLevelDBKey.mm index bd7b44a..e23f5b7 100644 --- a/Firestore/Source/Local/FSTLevelDBKey.mm +++ b/Firestore/Source/Local/FSTLevelDBKey.mm @@ -21,16 +21,19 @@ #include <vector> #import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Source/Model/FSTPath.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/ordered_code.h" +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" + +namespace util = firebase::firestore::util; namespace util = firebase::firestore::util; using firebase::firestore::model::ResourcePath; NS_ASSUME_NONNULL_BEGIN +using firebase::firestore::model::ResourcePath; using firebase::firestore::util::OrderedCode; using Firestore::StringView; using leveldb::Slice; @@ -255,10 +258,10 @@ BOOL ReadLabeledStringMatching(Slice *contents, * For each segment in the given resource path writes an FSTComponentLabelPathSegment component * label and a string containing the path segment. */ -void WriteResourcePath(std::string *dest, FSTResourcePath *path) { - for (int i = 0; i < path.length; i++) { +void WriteResourcePath(std::string *dest, const ResourcePath &path) { + for (const auto &segment : path) { WriteComponentLabel(dest, FSTComponentLabelPathSegment); - OrderedCode::WriteString(dest, StringView([path segmentAtIndex:i])); + OrderedCode::WriteString(dest, segment); } } @@ -522,7 +525,8 @@ NSString *InvalidKey(const Slice &key) { return result; } -+ (std::string)keyPrefixWithUserID:(StringView)userID resourcePath:(FSTResourcePath *)resourcePath { ++ (std::string)keyPrefixWithUserID:(StringView)userID + resourcePath:(const ResourcePath &)resourcePath { std::string result; WriteTableName(&result, kDocumentMutationsTable); WriteUserID(&result, userID); @@ -536,7 +540,7 @@ NSString *InvalidKey(const Slice &key) { std::string result; WriteTableName(&result, kDocumentMutationsTable); WriteUserID(&result, userID); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]); + WriteResourcePath(&result, documentKey.path); WriteBatchID(&result, batchID); WriteTerminator(&result); return result; @@ -690,7 +694,7 @@ NSString *InvalidKey(const Slice &key) { std::string result; WriteTableName(&result, kTargetDocumentsTable); WriteTargetID(&result, targetID); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]); + WriteResourcePath(&result, documentKey.path); WriteTerminator(&result); return result; } @@ -714,7 +718,7 @@ NSString *InvalidKey(const Slice &key) { return result; } -+ (std::string)keyPrefixWithResourcePath:(FSTResourcePath *)resourcePath { ++ (std::string)keyPrefixWithResourcePath:(const ResourcePath &)resourcePath { std::string result; WriteTableName(&result, kDocumentTargetsTable); WriteResourcePath(&result, resourcePath); @@ -724,7 +728,7 @@ NSString *InvalidKey(const Slice &key) { + (std::string)keyWithDocumentKey:(FSTDocumentKey *)documentKey targetID:(FSTTargetID)targetID { std::string result; WriteTableName(&result, kDocumentTargetsTable); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]); + WriteResourcePath(&result, documentKey.path); WriteTargetID(&result, targetID); WriteTerminator(&result); return result; @@ -749,7 +753,7 @@ NSString *InvalidKey(const Slice &key) { return result; } -+ (std::string)keyPrefixWithResourcePath:(FSTResourcePath *)path { ++ (std::string)keyPrefixWithResourcePath:(const ResourcePath &)path { std::string result; WriteTableName(&result, kRemoteDocumentsTable); WriteResourcePath(&result, path); @@ -759,7 +763,7 @@ NSString *InvalidKey(const Slice &key) { + (std::string)keyWithDocumentKey:(FSTDocumentKey *)key { std::string result; WriteTableName(&result, kRemoteDocumentsTable); - WriteResourcePath(&result, [FSTResourcePath resourcePathWithCPPResourcePath:key.path]); + WriteResourcePath(&result, key.path); WriteTerminator(&result); return result; } diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm index d7b5eca..ac93ab1 100644 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm @@ -30,10 +30,10 @@ #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" #include "Firestore/core/src/firebase/firestore/auth/user.h" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" #include "Firestore/core/src/firebase/firestore/util/string_util.h" @@ -42,6 +42,7 @@ NS_ASSUME_NONNULL_BEGIN namespace util = firebase::firestore::util; using Firestore::StringView; using firebase::firestore::auth::User; +using firebase::firestore::model::ResourcePath; using leveldb::DB; using leveldb::Iterator; using leveldb::ReadOptions; @@ -380,9 +381,8 @@ static ReadOptions StandardReadOptions() { NSString *userID = self.userID; // Scan the document-mutation index starting with a prefix starting with the given documentKey. - std::string indexPrefix = [FSTLevelDBDocumentMutationKey - keyPrefixWithUserID:self.userID - resourcePath:[FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]]; + std::string indexPrefix = + [FSTLevelDBDocumentMutationKey keyPrefixWithUserID:self.userID resourcePath:documentKey.path]; std::unique_ptr<Iterator> indexIterator(_db->NewIterator(StandardReadOptions())); indexIterator->Seek(indexPrefix); @@ -432,8 +432,8 @@ static ReadOptions StandardReadOptions() { FSTAssert(![query isDocumentQuery], @"Document queries shouldn't go down this path"); NSString *userID = self.userID; - FSTResourcePath *queryPath = [FSTResourcePath resourcePathWithCPPResourcePath:query.path]; - int immediateChildrenPathLength = queryPath.length + 1; + const ResourcePath &queryPath = query.path; + size_t immediateChildrenPathLength = queryPath.size() + 1; // TODO(mcg): Actually implement a single-collection query // @@ -620,9 +620,8 @@ static ReadOptions StandardReadOptions() { #pragma mark - FSTGarbageSource implementation - (BOOL)containsKey:(FSTDocumentKey *)documentKey { - std::string indexPrefix = [FSTLevelDBDocumentMutationKey - keyPrefixWithUserID:self.userID - resourcePath:[FSTResourcePath resourcePathWithCPPResourcePath:documentKey.path]]; + std::string indexPrefix = + [FSTLevelDBDocumentMutationKey keyPrefixWithUserID:self.userID resourcePath:documentKey.path]; std::unique_ptr<Iterator> indexIterator(_db->NewIterator(StandardReadOptions())); indexIterator->Seek(indexPrefix); diff --git a/Firestore/Source/Local/FSTLevelDBQueryCache.mm b/Firestore/Source/Local/FSTLevelDBQueryCache.mm index dcbcee1..fe1bf19 100644 --- a/Firestore/Source/Local/FSTLevelDBQueryCache.mm +++ b/Firestore/Source/Local/FSTLevelDBQueryCache.mm @@ -27,7 +27,6 @@ #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Local/FSTWriteGroup.h" #import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Util/FSTAssert.h" NS_ASSUME_NONNULL_BEGIN @@ -340,8 +339,7 @@ using leveldb::WriteOptions; #pragma mark - FSTGarbageSource implementation - (BOOL)containsKey:(FSTDocumentKey *)key { - std::string indexPrefix = [FSTLevelDBDocumentTargetKey - keyPrefixWithResourcePath:[FSTResourcePath resourcePathWithCPPResourcePath:key.path]]; + std::string indexPrefix = [FSTLevelDBDocumentTargetKey keyPrefixWithResourcePath:key.path]; std::unique_ptr<Iterator> indexIterator(_db->NewIterator([FSTLevelDB standardReadOptions])); indexIterator->Seek(indexPrefix); diff --git a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm index 423912f..c86318d 100644 --- a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm @@ -29,7 +29,6 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTDocumentSet.h" -#import "Firestore/Source/Model/FSTPath.h" #import "Firestore/Source/Util/FSTAssert.h" NS_ASSUME_NONNULL_BEGIN @@ -104,8 +103,7 @@ 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:[FSTResourcePath resourcePathWithCPPResourcePath:query.path]]; + std::string startKey = [FSTLevelDBRemoteDocumentKey keyPrefixWithResourcePath:query.path]; std::unique_ptr<Iterator> it(_db->NewIterator(StandardReadOptions())); it->Seek(startKey); diff --git a/Firestore/Source/Local/FSTLocalDocumentsView.mm b/Firestore/Source/Local/FSTLocalDocumentsView.mm index 0059e28..c059146 100644 --- a/Firestore/Source/Local/FSTLocalDocumentsView.mm +++ b/Firestore/Source/Local/FSTLocalDocumentsView.mm @@ -25,9 +25,12 @@ #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" +#include "Firestore/core/src/firebase/firestore/model/resource_path.h" + +using firebase::firestore::model::ResourcePath; + NS_ASSUME_NONNULL_BEGIN @interface FSTLocalDocumentsView () @@ -76,18 +79,16 @@ NS_ASSUME_NONNULL_BEGIN - (FSTDocumentDictionary *)documentsMatchingQuery:(FSTQuery *)query { if ([FSTDocumentKey isDocumentKey:query.path]) { - return [self documentsMatchingDocumentQuery:[FSTResourcePath - resourcePathWithCPPResourcePath:query.path]]; + return [self documentsMatchingDocumentQuery:query.path]; } else { return [self documentsMatchingCollectionQuery:query]; } } -- (FSTDocumentDictionary *)documentsMatchingDocumentQuery:(FSTResourcePath *)docPath { +- (FSTDocumentDictionary *)documentsMatchingDocumentQuery:(const ResourcePath &)docPath { FSTDocumentDictionary *result = [FSTDocumentDictionary documentDictionary]; // Just do a simple document lookup. - FSTMaybeDocument *doc = - [self documentForKey:[FSTDocumentKey keyWithPath:[docPath toCPPResourcePath]]]; + FSTMaybeDocument *doc = [self documentForKey:[FSTDocumentKey keyWithPath:docPath]]; if ([doc isKindOfClass:[FSTDocument class]]) { result = [result dictionaryBySettingObject:(FSTDocument *)doc forKey:doc.key]; } diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.mm b/Firestore/Source/Local/FSTMemoryMutationQueue.mm index 7e5cc02..8375efd 100644 --- a/Firestore/Source/Local/FSTMemoryMutationQueue.mm +++ b/Firestore/Source/Local/FSTMemoryMutationQueue.mm @@ -21,7 +21,6 @@ #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" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" diff --git a/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm b/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm index b0d6807..fed608c 100644 --- a/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTMemoryRemoteDocumentCache.mm @@ -20,7 +20,6 @@ #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTDocumentDictionary.h" #import "Firestore/Source/Model/FSTDocumentKey.h" -#import "Firestore/Source/Model/FSTPath.h" NS_ASSUME_NONNULL_BEGIN |