diff --git a/Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm b/Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm index 6c6a91b6621..3a1f5b78876 100644 --- a/Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm +++ b/Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm @@ -24,13 +24,13 @@ #import "FIRTimestamp.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" #import "Firestore/Source/Local/FSTLRUGarbageCollector.h" -#import "Firestore/Source/Local/FSTMutationQueue.h" #import "Firestore/Source/Local/FSTPersistence.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Util/FSTClasses.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" +#include "Firestore/core/src/firebase/firestore/local/mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/query_cache.h" #include "Firestore/core/src/firebase/firestore/local/reference_set.h" #include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h" @@ -44,6 +44,7 @@ using firebase::firestore::auth::User; using firebase::firestore::local::LruParams; using firebase::firestore::local::LruResults; +using firebase::firestore::local::MutationQueue; using firebase::firestore::local::QueryCache; using firebase::firestore::local::ReferenceSet; using firebase::firestore::local::RemoteDocumentCache; @@ -64,7 +65,7 @@ @implementation FSTLRUGarbageCollectorTests { id _persistence; QueryCache *_queryCache; RemoteDocumentCache *_documentCache; - id _mutationQueue; + MutationQueue *_mutationQueue; id _lruDelegate; FSTLRUGarbageCollector *_gc; ListenSequenceNumber _initialSequenceNumber; @@ -96,7 +97,7 @@ - (void)newTestResourcesWithLruParams:(LruParams)lruParams { _mutationQueue = [_persistence mutationQueueForUser:_user]; _lruDelegate = (id)_persistence.referenceDelegate; _initialSequenceNumber = _persistence.run("start querycache", [&]() -> ListenSequenceNumber { - [_mutationQueue start]; + _mutationQueue->Start(); _gc = _lruDelegate.gc; return _persistence.currentSequenceNumber; }); @@ -447,7 +448,7 @@ - (void)testRemoveOrphanedDocuments { // serve to keep the mutated documents from being GC'd while the mutations are outstanding. _persistence.run("actually register the mutations", [&]() { FIRTimestamp *writeTime = [FIRTimestamp timestamp]; - [_mutationQueue addMutationBatchWithWriteTime:writeTime mutations:mutations]; + _mutationQueue->AddMutationBatch(writeTime, mutations); }); // Mark 5 documents eligible for GC. This simulates documents that were mutated then ack'd. diff --git a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm index d4d46a496ba..79a9b977e1c 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm @@ -23,7 +23,6 @@ #import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" #import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h" #import "Firestore/Source/Local/FSTLevelDB.h" -#import "Firestore/Source/Local/FSTLevelDBMutationQueue.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_key.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_migrations.h" diff --git a/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm index 917f163c179..d24e24a0818 100644 --- a/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTLevelDBMutationQueueTests.mm @@ -14,8 +14,6 @@ * limitations under the License. */ -#import "Firestore/Source/Local/FSTLevelDBMutationQueue.h" - #import #include @@ -81,7 +79,7 @@ - (void)setUp { _db = [FSTPersistenceTestHelpers levelDBPersistence]; [_db.referenceDelegate addInMemoryPins:&_additionalReferences]; - self.mutationQueue = [_db mutationQueueForUser:User("user")].mutationQueue; + self.mutationQueue = [_db mutationQueueForUser:User("user")]; self.persistence = _db; self.persistence.run("Setup", [&]() { self.mutationQueue->Start(); }); diff --git a/Firestore/Example/Tests/Local/FSTMemoryMutationQueueTests.mm b/Firestore/Example/Tests/Local/FSTMemoryMutationQueueTests.mm index bb2ff6c4018..0d54f4466ec 100644 --- a/Firestore/Example/Tests/Local/FSTMemoryMutationQueueTests.mm +++ b/Firestore/Example/Tests/Local/FSTMemoryMutationQueueTests.mm @@ -14,8 +14,6 @@ * limitations under the License. */ -#import "Firestore/Source/Local/FSTMemoryMutationQueue.h" - #import "Firestore/Source/Local/FSTMemoryPersistence.h" #import "Firestore/Example/Tests/Local/FSTMutationQueueTests.h" @@ -43,7 +41,7 @@ - (void)setUp { self.persistence = [FSTPersistenceTestHelpers eagerGCMemoryPersistence]; [self.persistence.referenceDelegate addInMemoryPins:&_additionalReferences]; - self.mutationQueue = [self.persistence mutationQueueForUser:User("user")].mutationQueue; + self.mutationQueue = [self.persistence mutationQueueForUser:User("user")]; } @end diff --git a/Firestore/Source/Local/FSTLRUGarbageCollector.mm b/Firestore/Source/Local/FSTLRUGarbageCollector.mm index 2071a35b977..b47a833857a 100644 --- a/Firestore/Source/Local/FSTLRUGarbageCollector.mm +++ b/Firestore/Source/Local/FSTLRUGarbageCollector.mm @@ -20,7 +20,6 @@ #include #include -#import "Firestore/Source/Local/FSTMutationQueue.h" #import "Firestore/Source/Local/FSTPersistence.h" #include "Firestore/core/include/firebase/firestore/timestamp.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" diff --git a/Firestore/Source/Local/FSTLevelDB.mm b/Firestore/Source/Local/FSTLevelDB.mm index c451aa9b262..ae010cfc272 100644 --- a/Firestore/Source/Local/FSTLevelDB.mm +++ b/Firestore/Source/Local/FSTLevelDB.mm @@ -22,7 +22,6 @@ #import "FIRFirestoreErrors.h" #import "Firestore/Source/Local/FSTLRUGarbageCollector.h" -#import "Firestore/Source/Local/FSTLevelDBMutationQueue.h" #import "Firestore/Source/Remote/FSTSerializerBeta.h" #include "Firestore/core/include/firebase/firestore/firestore_errors.h" @@ -30,6 +29,7 @@ #include "Firestore/core/src/firebase/firestore/core/database_info.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_key.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_migrations.h" +#include "Firestore/core/src/firebase/firestore/local/leveldb_mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_query_cache.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_remote_document_cache.h" #include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" @@ -63,6 +63,7 @@ using firebase::firestore::local::LevelDbDocumentTargetKey; using firebase::firestore::local::LevelDbMigrations; using firebase::firestore::local::LevelDbMutationKey; +using firebase::firestore::local::LevelDbMutationQueue; using firebase::firestore::local::LevelDbQueryCache; using firebase::firestore::local::LevelDbRemoteDocumentCache; using firebase::firestore::local::LevelDbTransaction; @@ -93,7 +94,9 @@ - (size_t)byteSize; @property(nonatomic, assign, getter=isStarted) BOOL started; -- (firebase::firestore::local::LevelDbQueryCache *)queryCache; +- (LevelDbQueryCache *)queryCache; + +- (LevelDbMutationQueue *)mutationQueueForUser:(const User &)user; @end @@ -280,6 +283,7 @@ @implementation FSTLevelDB { FSTLevelDBLRUDelegate *_referenceDelegate; std::unique_ptr _queryCache; std::set _users; + std::unique_ptr _currentMutationQueue; } /** @@ -463,9 +467,10 @@ - (LevelDbTransaction *)currentTransaction { #pragma mark - Persistence Factory methods -- (id)mutationQueueForUser:(const User &)user { +- (LevelDbMutationQueue *)mutationQueueForUser:(const User &)user { _users.insert(user.uid()); - return [FSTLevelDBMutationQueue mutationQueueWithUser:user db:self serializer:self.serializer]; + _currentMutationQueue.reset(new LevelDbMutationQueue(user, self, self.serializer)); + return _currentMutationQueue.get(); } - (LevelDbQueryCache *)queryCache { diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.h b/Firestore/Source/Local/FSTLevelDBMutationQueue.h deleted file mode 100644 index 72fde7d1ba8..00000000000 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -#include - -#import "Firestore/Source/Local/FSTMutationQueue.h" - -#include "Firestore/core/src/firebase/firestore/auth/user.h" -#include "Firestore/core/src/firebase/firestore/local/leveldb_mutation_queue.h" -#include "Firestore/core/src/firebase/firestore/model/types.h" -#include "leveldb/db.h" - -@class FSTLevelDB; -@class FSTLocalSerializer; - -NS_ASSUME_NONNULL_BEGIN - -/** A mutation queue for a specific user, backed by LevelDB. */ -@interface FSTLevelDBMutationQueue : NSObject - -- (instancetype)init __attribute__((unavailable("Use a static constructor"))); - -/** - * Creates a new mutation queue for the given user, in the given LevelDB. - * - * @param user The user for which to create a mutation queue. - * @param db The LevelDB in which to create the queue. - */ -+ (instancetype)mutationQueueWithUser:(const firebase::firestore::auth::User &)user - db:(FSTLevelDB *)db - serializer:(FSTLocalSerializer *)serializer; - -- (firebase::firestore::local::LevelDbMutationQueue *)mutationQueue; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm b/Firestore/Source/Local/FSTLevelDBMutationQueue.mm deleted file mode 100644 index 7753db22f12..00000000000 --- a/Firestore/Source/Local/FSTLevelDBMutationQueue.mm +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "Firestore/Source/Local/FSTLevelDBMutationQueue.h" - -#include -#include -#include -#include -#include - -#import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" -#import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Local/FSTLevelDB.h" -#import "Firestore/Source/Local/FSTLocalSerializer.h" -#import "Firestore/Source/Model/FSTMutation.h" -#import "Firestore/Source/Model/FSTMutationBatch.h" - -#include "Firestore/core/src/firebase/firestore/auth/user.h" -#include "Firestore/core/src/firebase/firestore/local/leveldb_key.h" -#include "Firestore/core/src/firebase/firestore/local/leveldb_mutation_queue.h" -#include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h" -#include "Firestore/core/src/firebase/firestore/local/leveldb_util.h" -#include "Firestore/core/src/firebase/firestore/model/mutation_batch.h" -#include "Firestore/core/src/firebase/firestore/model/resource_path.h" -#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" -#include "Firestore/core/src/firebase/firestore/util/string_apple.h" -#include "Firestore/core/src/firebase/firestore/util/string_util.h" -#include "absl/memory/memory.h" -#include "absl/strings/match.h" -#include "leveldb/db.h" -#include "leveldb/write_batch.h" - -NS_ASSUME_NONNULL_BEGIN - -namespace util = firebase::firestore::util; -using firebase::firestore::auth::User; -using firebase::firestore::local::DescribeKey; -using firebase::firestore::local::LevelDbDocumentMutationKey; -using firebase::firestore::local::LevelDbMutationKey; -using firebase::firestore::local::LevelDbMutationQueue; -using firebase::firestore::local::LevelDbMutationQueueKey; -using firebase::firestore::local::LevelDbTransaction; -using firebase::firestore::local::LoadNextBatchIdFromDb; -using firebase::firestore::local::MakeStringView; -using firebase::firestore::model::BatchId; -using firebase::firestore::model::kBatchIdUnknown; -using firebase::firestore::model::DocumentKey; -using firebase::firestore::model::DocumentKeySet; -using firebase::firestore::model::ResourcePath; -using leveldb::DB; -using leveldb::Iterator; -using leveldb::ReadOptions; -using leveldb::Slice; -using leveldb::Status; -using leveldb::WriteBatch; -using leveldb::WriteOptions; - -static NSArray *toNSArray(const std::vector &vec) { - NSMutableArray *copy = [NSMutableArray array]; - for (auto &batch : vec) { - [copy addObject:batch]; - } - return copy; -} - -@interface FSTLevelDBMutationQueue () - -- (instancetype)initWithUserID:(std::string)userID - db:(FSTLevelDB *)db - serializer:(FSTLocalSerializer *)serializer - delegate:(std::unique_ptr)delegate - NS_DESIGNATED_INITIALIZER; - -@end - -@implementation FSTLevelDBMutationQueue { - std::unique_ptr _delegate; -} - -+ (instancetype)mutationQueueWithUser:(const User &)user - db:(FSTLevelDB *)db - serializer:(FSTLocalSerializer *)serializer { - std::string userID = user.is_authenticated() ? user.uid() : ""; - - return [[FSTLevelDBMutationQueue alloc] - initWithUserID:std::move(userID) - db:db - serializer:serializer - delegate:absl::make_unique(user, db, serializer)]; -} - -- (instancetype)initWithUserID:(std::string)userID - db:(FSTLevelDB *)db - serializer:(FSTLocalSerializer *)serializer - delegate:(std::unique_ptr)delegate { - if (self = [super init]) { - _delegate = std::move(delegate); - } - return self; -} - -- (void)start { - _delegate->Start(); -} - -- (BOOL)isEmpty { - return _delegate->IsEmpty(); -} - -- (void)acknowledgeBatch:(FSTMutationBatch *)batch streamToken:(nullable NSData *)streamToken { - _delegate->AcknowledgeBatch(batch, streamToken); -} - -- (nullable NSData *)lastStreamToken { - return _delegate->GetLastStreamToken(); -} - -- (void)setLastStreamToken:(nullable NSData *)streamToken { - _delegate->SetLastStreamToken(streamToken); -} - -- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime - mutations:(NSArray *)mutations { - return _delegate->AddMutationBatch(localWriteTime, mutations); -} - -- (nullable FSTMutationBatch *)lookupMutationBatch:(BatchId)batchID { - return _delegate->LookupMutationBatch(batchID); -} - -- (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID:(BatchId)batchID { - return _delegate->NextMutationBatchAfterBatchId(batchID); -} - -- (NSArray *)allMutationBatchesAffectingDocumentKey: - (const DocumentKey &)documentKey { - return toNSArray(_delegate->AllMutationBatchesAffectingDocumentKey(documentKey)); -} - -- (NSArray *)allMutationBatchesAffectingDocumentKeys: - (const DocumentKeySet &)documentKeys { - return toNSArray(_delegate->AllMutationBatchesAffectingDocumentKeys(documentKeys)); -} - -- (NSArray *)allMutationBatchesAffectingQuery:(FSTQuery *)query { - return toNSArray(_delegate->AllMutationBatchesAffectingQuery(query)); -} - -- (NSArray *)allMutationBatches { - return toNSArray(_delegate->AllMutationBatches()); -} - -- (void)removeMutationBatch:(FSTMutationBatch *)batch { - _delegate->RemoveMutationBatch(batch); -} - -- (void)performConsistencyCheck { - _delegate->PerformConsistencyCheck(); -} - -- (LevelDbMutationQueue *)mutationQueue { - return _delegate.get(); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Local/FSTLocalDocumentsView.h b/Firestore/Source/Local/FSTLocalDocumentsView.h index a559b7c2136..730e0ea47bc 100644 --- a/Firestore/Source/Local/FSTLocalDocumentsView.h +++ b/Firestore/Source/Local/FSTLocalDocumentsView.h @@ -16,6 +16,7 @@ #import +#include "Firestore/core/src/firebase/firestore/local/mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/document_key_set.h" @@ -23,7 +24,6 @@ @class FSTMaybeDocument; @class FSTQuery; -@protocol FSTMutationQueue; NS_ASSUME_NONNULL_BEGIN @@ -36,7 +36,8 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)viewWithRemoteDocumentCache: (firebase::firestore::local::RemoteDocumentCache *)remoteDocumentCache - mutationQueue:(id)mutationQueue; + mutationQueue: + (firebase::firestore::local::MutationQueue *)mutationQueue; - (instancetype)init __attribute__((unavailable("Use a static constructor"))); diff --git a/Firestore/Source/Local/FSTLocalDocumentsView.mm b/Firestore/Source/Local/FSTLocalDocumentsView.mm index bdc92a8dc08..eb11d3ca0ab 100644 --- a/Firestore/Source/Local/FSTLocalDocumentsView.mm +++ b/Firestore/Source/Local/FSTLocalDocumentsView.mm @@ -16,12 +16,14 @@ #import "Firestore/Source/Local/FSTLocalDocumentsView.h" +#include + #import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Local/FSTMutationQueue.h" #import "Firestore/Source/Model/FSTDocument.h" #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Model/FSTMutationBatch.h" +#include "Firestore/core/src/firebase/firestore/local/mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/document_map.h" @@ -29,6 +31,7 @@ #include "Firestore/core/src/firebase/firestore/model/snapshot_version.h" #include "Firestore/core/src/firebase/firestore/util/hard_assert.h" +using firebase::firestore::local::MutationQueue; using firebase::firestore::local::RemoteDocumentCache; using firebase::firestore::model::DocumentKey; using firebase::firestore::model::DocumentKeySet; @@ -41,24 +44,24 @@ @interface FSTLocalDocumentsView () - (instancetype)initWithRemoteDocumentCache:(RemoteDocumentCache *)remoteDocumentCache - mutationQueue:(id)mutationQueue + mutationQueue:(MutationQueue *)mutationQueue NS_DESIGNATED_INITIALIZER; -@property(nonatomic, strong, readonly) id mutationQueue; @end @implementation FSTLocalDocumentsView { RemoteDocumentCache *_remoteDocumentCache; + MutationQueue *_mutationQueue; } + (instancetype)viewWithRemoteDocumentCache:(RemoteDocumentCache *)remoteDocumentCache - mutationQueue:(id)mutationQueue { + mutationQueue:(MutationQueue *)mutationQueue { return [[FSTLocalDocumentsView alloc] initWithRemoteDocumentCache:remoteDocumentCache mutationQueue:mutationQueue]; } - (instancetype)initWithRemoteDocumentCache:(RemoteDocumentCache *)remoteDocumentCache - mutationQueue:(id)mutationQueue { + mutationQueue:(MutationQueue *)mutationQueue { if (self = [super init]) { _remoteDocumentCache = remoteDocumentCache; _mutationQueue = mutationQueue; @@ -67,16 +70,16 @@ - (instancetype)initWithRemoteDocumentCache:(RemoteDocumentCache *)remoteDocumen } - (nullable FSTMaybeDocument *)documentForKey:(const DocumentKey &)key { - NSArray *batches = - [self.mutationQueue allMutationBatchesAffectingDocumentKey:key]; + std::vector batches = + _mutationQueue->AllMutationBatchesAffectingDocumentKey(key); return [self documentForKey:key inBatches:batches]; } // Internal version of documentForKey: which allows reusing `batches`. - (nullable FSTMaybeDocument *)documentForKey:(const DocumentKey &)key - inBatches:(NSArray *)batches { + inBatches:(const std::vector &)batches { FSTMaybeDocument *_Nullable document = _remoteDocumentCache->Get(key); - for (FSTMutationBatch *batch in batches) { + for (FSTMutationBatch *batch : batches) { document = [batch applyToLocalDocument:document documentKey:key]; } @@ -86,13 +89,14 @@ - (nullable FSTMaybeDocument *)documentForKey:(const DocumentKey &)key // Returns the view of the given `docs` as they would appear after applying all // mutations in the given `batches`. - (MaybeDocumentMap)applyLocalMutationsToDocuments:(const MaybeDocumentMap &)docs - fromBatches:(NSArray *)batches { + fromBatches: + (const std::vector &)batches { MaybeDocumentMap results; for (const auto &kv : docs) { const DocumentKey &key = kv.first; FSTMaybeDocument *localView = kv.second; - for (FSTMutationBatch *batch in batches) { + for (FSTMutationBatch *batch : batches) { localView = [batch applyToLocalDocument:localView documentKey:key]; } results = results.insert(key, localView); @@ -116,8 +120,8 @@ - (MaybeDocumentMap)localViewsForDocuments:(const MaybeDocumentMap &)baseDocs { for (const auto &kv : baseDocs) { allKeys = allKeys.insert(kv.first); } - NSArray *batches = - [self.mutationQueue allMutationBatchesAffectingDocumentKeys:allKeys]; + std::vector batches = + _mutationQueue->AllMutationBatchesAffectingDocumentKeys(allKeys); MaybeDocumentMap docs = [self applyLocalMutationsToDocuments:baseDocs fromBatches:batches]; @@ -158,10 +162,10 @@ - (DocumentMap)documentsMatchingDocumentQuery:(const ResourcePath &)docPath { - (DocumentMap)documentsMatchingCollectionQuery:(FSTQuery *)query { DocumentMap results = _remoteDocumentCache->GetMatching(query); // Get locally persisted mutation batches. - NSArray *matchingBatches = - [self.mutationQueue allMutationBatchesAffectingQuery:query]; + std::vector matchingBatches = + _mutationQueue->AllMutationBatchesAffectingQuery(query); - for (FSTMutationBatch *batch in matchingBatches) { + for (FSTMutationBatch *batch : matchingBatches) { for (FSTMutation *mutation in batch.mutations) { // Only process documents belonging to the collection. if (!query.path.IsImmediateParentOf(mutation.key.path())) { diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm index 64e452b825c..329b7451e59 100644 --- a/Firestore/Source/Local/FSTLocalStore.mm +++ b/Firestore/Source/Local/FSTLocalStore.mm @@ -19,6 +19,7 @@ #include #include #include +#include #import "FIRTimestamp.h" #import "Firestore/Source/Core/FSTQuery.h" @@ -26,7 +27,6 @@ #import "Firestore/Source/Local/FSTLocalDocumentsView.h" #import "Firestore/Source/Local/FSTLocalViewChanges.h" #import "Firestore/Source/Local/FSTLocalWriteResult.h" -#import "Firestore/Source/Local/FSTMutationQueue.h" #import "Firestore/Source/Local/FSTPersistence.h" #import "Firestore/Source/Local/FSTQueryData.h" #import "Firestore/Source/Model/FSTDocument.h" @@ -37,6 +37,7 @@ #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/core/target_id_generator.h" #include "Firestore/core/src/firebase/firestore/immutable/sorted_set.h" +#include "Firestore/core/src/firebase/firestore/local/mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/query_cache.h" #include "Firestore/core/src/firebase/firestore/local/reference_set.h" #include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h" @@ -47,6 +48,7 @@ using firebase::firestore::auth::User; using firebase::firestore::core::TargetIdGenerator; using firebase::firestore::local::LruResults; +using firebase::firestore::local::MutationQueue; using firebase::firestore::local::QueryCache; using firebase::firestore::local::ReferenceSet; using firebase::firestore::local::RemoteDocumentCache; @@ -75,11 +77,8 @@ @interface FSTLocalStore () /** Manages our in-memory or durable persistence. */ @property(nonatomic, strong, readonly) id persistence; -/** The set of all mutations that have been sent but not yet been applied to the backend. */ -@property(nonatomic, strong) id mutationQueue; - /** The "local" view of all documents (layering mutationQueue on top of remoteDocumentCache). */ -@property(nonatomic, strong) FSTLocalDocumentsView *localDocuments; +@property(nonatomic, nullable, strong) FSTLocalDocumentsView *localDocuments; /** Maps a query to the data about that query. */ @property(nonatomic) QueryCache *queryCache; @@ -92,6 +91,8 @@ @implementation FSTLocalStore { /** The set of all cached remote documents. */ RemoteDocumentCache *_remoteDocumentCache; QueryCache *_queryCache; + /** The set of all mutations that have been sent but not yet been applied to the backend. */ + MutationQueue *_mutationQueue; /** The set of document references maintained by any local views. */ ReferenceSet _localViewReferences; @@ -123,30 +124,32 @@ - (void)start { } - (void)startMutationQueue { - self.persistence.run("Start MutationQueue", [&]() { [self.mutationQueue start]; }); + self.persistence.run("Start MutationQueue", [&]() { _mutationQueue->Start(); }); } - (MaybeDocumentMap)userDidChange:(const User &)user { // Swap out the mutation queue, grabbing the pending mutation batches before and after. - NSArray *oldBatches = self.persistence.run( + std::vector oldBatches = self.persistence.run( "OldBatches", - [&]() -> NSArray * { return [self.mutationQueue allMutationBatches]; }); + [&]() -> std::vector { return _mutationQueue->AllMutationBatches(); }); - self.mutationQueue = [self.persistence mutationQueueForUser:user]; + // The old one has a reference to the mutation queue, so nil it out first. + self.localDocuments = nil; + _mutationQueue = [self.persistence mutationQueueForUser:user]; [self startMutationQueue]; return self.persistence.run("NewBatches", [&]() -> MaybeDocumentMap { - NSArray *newBatches = [self.mutationQueue allMutationBatches]; + std::vector newBatches = _mutationQueue->AllMutationBatches(); // Recreate our LocalDocumentsView using the new MutationQueue. self.localDocuments = [FSTLocalDocumentsView viewWithRemoteDocumentCache:_remoteDocumentCache - mutationQueue:self.mutationQueue]; + mutationQueue:_mutationQueue]; // Union the old/new changed keys. DocumentKeySet changedKeys; - for (NSArray *batches in @[ oldBatches, newBatches ]) { - for (FSTMutationBatch *batch in batches) { + for (const std::vector &batches : {oldBatches, newBatches}) { + for (FSTMutationBatch *batch : batches) { for (FSTMutation *mutation in batch.mutations) { changedKeys = changedKeys.insert(mutation.key); } @@ -161,8 +164,7 @@ - (MaybeDocumentMap)userDidChange:(const User &)user { - (FSTLocalWriteResult *)locallyWriteMutations:(NSArray *)mutations { return self.persistence.run("Locally write mutations", [&]() -> FSTLocalWriteResult * { FIRTimestamp *localWriteTime = [FIRTimestamp timestamp]; - FSTMutationBatch *batch = [self.mutationQueue addMutationBatchWithWriteTime:localWriteTime - mutations:mutations]; + FSTMutationBatch *batch = _mutationQueue->AddMutationBatch(localWriteTime, mutations); DocumentKeySet keys = [batch keys]; MaybeDocumentMap changedDocuments = [self.localDocuments documentsForKeys:keys]; return [FSTLocalWriteResult resultForBatchID:batch.batchID changes:std::move(changedDocuments)]; @@ -171,12 +173,10 @@ - (FSTLocalWriteResult *)locallyWriteMutations:(NSArray *)mutatio - (MaybeDocumentMap)acknowledgeBatchWithResult:(FSTMutationBatchResult *)batchResult { return self.persistence.run("Acknowledge batch", [&]() -> MaybeDocumentMap { - id mutationQueue = self.mutationQueue; - FSTMutationBatch *batch = batchResult.batch; - [mutationQueue acknowledgeBatch:batch streamToken:batchResult.streamToken]; + _mutationQueue->AcknowledgeBatch(batch, batchResult.streamToken); [self applyBatchResult:batchResult]; - [self.mutationQueue performConsistencyCheck]; + _mutationQueue->PerformConsistencyCheck(); return [self.localDocuments documentsForKeys:batch.keys]; }); @@ -184,23 +184,23 @@ - (MaybeDocumentMap)acknowledgeBatchWithResult:(FSTMutationBatchResult *)batchRe - (MaybeDocumentMap)rejectBatchID:(BatchId)batchID { return self.persistence.run("Reject batch", [&]() -> MaybeDocumentMap { - FSTMutationBatch *toReject = [self.mutationQueue lookupMutationBatch:batchID]; + FSTMutationBatch *toReject = _mutationQueue->LookupMutationBatch(batchID); HARD_ASSERT(toReject, "Attempt to reject nonexistent batch!"); - [self.mutationQueue removeMutationBatch:toReject]; - [self.mutationQueue performConsistencyCheck]; + _mutationQueue->RemoveMutationBatch(toReject); + _mutationQueue->PerformConsistencyCheck(); return [self.localDocuments documentsForKeys:toReject.keys]; }); } - (nullable NSData *)lastStreamToken { - return [self.mutationQueue lastStreamToken]; + return _mutationQueue->GetLastStreamToken(); } - (void)setLastStreamToken:(nullable NSData *)streamToken { self.persistence.run("Set stream token", - [&]() { [self.mutationQueue setLastStreamToken:streamToken]; }); + [&]() { _mutationQueue->SetLastStreamToken(streamToken); }); } - (const SnapshotVersion &)lastRemoteSnapshotVersion { @@ -367,7 +367,7 @@ - (void)notifyLocalViewChanges:(NSArray *)viewChanges { - (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID:(BatchId)batchID { FSTMutationBatch *result = self.persistence.run("NextMutationBatchAfterBatchID", [&]() -> FSTMutationBatch * { - return [self.mutationQueue nextMutationBatchAfterBatchID:batchID]; + return _mutationQueue->NextMutationBatchAfterBatchId(batchID); }); return result; } @@ -464,7 +464,7 @@ - (void)applyBatchResult:(FSTMutationBatchResult *)batchResult { } } - [self.mutationQueue removeMutationBatch:batch]; + _mutationQueue->RemoveMutationBatch(batch); } - (LruResults)collectGarbage:(FSTLRUGarbageCollector *)garbageCollector { diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.h b/Firestore/Source/Local/FSTMemoryMutationQueue.h deleted file mode 100644 index 3a7808d0ebb..00000000000 --- a/Firestore/Source/Local/FSTMemoryMutationQueue.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -#import "Firestore/Source/Local/FSTMemoryPersistence.h" -#import "Firestore/Source/Local/FSTMutationQueue.h" - -NS_ASSUME_NONNULL_BEGIN - -@class FSTLocalSerializer; - -@interface FSTMemoryMutationQueue : NSObject - -- (instancetype)initWithPersistence:(FSTMemoryPersistence *)persistence NS_DESIGNATED_INITIALIZER; - -- (instancetype)init NS_UNAVAILABLE; - -/** - * Checks to see if there are any references to a document with the given key. - */ -- (BOOL)containsKey:(const firebase::firestore::model::DocumentKey &)key; - -- (size_t)byteSizeWithSerializer:(FSTLocalSerializer *)serializer; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Local/FSTMemoryMutationQueue.mm b/Firestore/Source/Local/FSTMemoryMutationQueue.mm deleted file mode 100644 index a8a50732fa3..00000000000 --- a/Firestore/Source/Local/FSTMemoryMutationQueue.mm +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "Firestore/Source/Local/FSTMemoryMutationQueue.h" - -#import - -#include -#include - -#import "Firestore/Protos/objc/firestore/local/Mutation.pbobjc.h" -#import "Firestore/Source/Core/FSTQuery.h" -#import "Firestore/Source/Local/FSTMemoryPersistence.h" -#import "Firestore/Source/Model/FSTMutation.h" -#import "Firestore/Source/Model/FSTMutationBatch.h" - -#include "Firestore/core/src/firebase/firestore/immutable/sorted_set.h" -#include "Firestore/core/src/firebase/firestore/local/document_reference.h" -#include "Firestore/core/src/firebase/firestore/local/memory_mutation_queue.h" -#include "Firestore/core/src/firebase/firestore/model/document_key.h" -#include "Firestore/core/src/firebase/firestore/model/resource_path.h" -#include "Firestore/core/src/firebase/firestore/util/hard_assert.h" -#include "absl/memory/memory.h" - -using firebase::firestore::immutable::SortedSet; -using firebase::firestore::local::DocumentReference; -using firebase::firestore::local::MemoryMutationQueue; -using firebase::firestore::model::BatchId; -using firebase::firestore::model::DocumentKey; -using firebase::firestore::model::DocumentKeySet; -using firebase::firestore::model::ResourcePath; - -NS_ASSUME_NONNULL_BEGIN - -static NSArray *toNSArray(const std::vector &vec) { - NSMutableArray *copy = [NSMutableArray array]; - for (auto &batch : vec) { - [copy addObject:batch]; - } - return copy; -} - -@interface FSTMemoryMutationQueue () - -- (MemoryMutationQueue *)mutationQueue; - -@end - -@implementation FSTMemoryMutationQueue { - std::unique_ptr _delegate; -} - -- (instancetype)initWithPersistence:(FSTMemoryPersistence *)persistence { - if (self = [super init]) { - _delegate = absl::make_unique(persistence); - } - return self; -} - -- (void)setLastStreamToken:(NSData *_Nullable)streamToken { - _delegate->SetLastStreamToken(streamToken); -} - -- (NSData *_Nullable)lastStreamToken { - return _delegate->GetLastStreamToken(); -} - -#pragma mark - FSTMutationQueue implementation - -- (void)start { - _delegate->Start(); -} - -- (BOOL)isEmpty { - return _delegate->IsEmpty(); -} - -- (void)acknowledgeBatch:(FSTMutationBatch *)batch streamToken:(nullable NSData *)streamToken { - _delegate->AcknowledgeBatch(batch, streamToken); -} - -- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime - mutations:(NSArray *)mutations { - return _delegate->AddMutationBatch(localWriteTime, mutations); -} - -- (nullable FSTMutationBatch *)lookupMutationBatch:(BatchId)batchID { - return _delegate->LookupMutationBatch(batchID); -} - -- (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID:(BatchId)batchID { - return _delegate->NextMutationBatchAfterBatchId(batchID); -} - -- (NSArray *)allMutationBatches { - return toNSArray(_delegate->AllMutationBatches()); -} - -- (NSArray *)allMutationBatchesAffectingDocumentKey: - (const DocumentKey &)documentKey { - return toNSArray(_delegate->AllMutationBatchesAffectingDocumentKey(documentKey)); -} - -- (NSArray *)allMutationBatchesAffectingDocumentKeys: - (const DocumentKeySet &)documentKeys { - return toNSArray(_delegate->AllMutationBatchesAffectingDocumentKeys(documentKeys)); -} - -- (NSArray *)allMutationBatchesAffectingQuery:(FSTQuery *)query { - return toNSArray(_delegate->AllMutationBatchesAffectingQuery(query)); -} - -- (void)removeMutationBatch:(FSTMutationBatch *)batch { - _delegate->RemoveMutationBatch(batch); -} - -- (void)performConsistencyCheck { - _delegate->PerformConsistencyCheck(); -} - -#pragma mark - FSTGarbageSource implementation - -- (BOOL)containsKey:(const DocumentKey &)key { - return _delegate->ContainsKey(key); -} - -#pragma mark - Helpers - -- (size_t)byteSizeWithSerializer:(FSTLocalSerializer *)serializer { - return _delegate->CalculateByteSize(serializer); -} - -- (MemoryMutationQueue *)mutationQueue { - return _delegate.get(); -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Local/FSTMemoryPersistence.mm b/Firestore/Source/Local/FSTMemoryPersistence.mm index f90d9f3c826..6dc197cab32 100644 --- a/Firestore/Source/Local/FSTMemoryPersistence.mm +++ b/Firestore/Source/Local/FSTMemoryPersistence.mm @@ -21,21 +21,21 @@ #include #include -#import "Firestore/Source/Local/FSTMemoryMutationQueue.h" -#include "absl/memory/memory.h" - #include "Firestore/core/src/firebase/firestore/auth/user.h" #include "Firestore/core/src/firebase/firestore/local/listen_sequence.h" +#include "Firestore/core/src/firebase/firestore/local/memory_mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/memory_query_cache.h" #include "Firestore/core/src/firebase/firestore/local/memory_remote_document_cache.h" #include "Firestore/core/src/firebase/firestore/local/reference_set.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/util/hard_assert.h" +#include "absl/memory/memory.h" using firebase::firestore::auth::HashUser; using firebase::firestore::auth::User; using firebase::firestore::local::ListenSequence; using firebase::firestore::local::LruParams; +using firebase::firestore::local::MemoryMutationQueue; using firebase::firestore::local::MemoryQueryCache; using firebase::firestore::local::MemoryRemoteDocumentCache; using firebase::firestore::local::ReferenceSet; @@ -45,7 +45,7 @@ using firebase::firestore::model::TargetId; using firebase::firestore::util::Status; -using MutationQueues = std::unordered_map; +using MutationQueues = std::unordered_map, HashUser>; NS_ASSUME_NONNULL_BEGIN @@ -55,6 +55,8 @@ - (MemoryQueryCache *)queryCache; - (MemoryRemoteDocumentCache *)remoteDocumentCache; +- (MemoryMutationQueue *)mutationQueueForUser:(const User &)user; + @property(nonatomic, readonly) MutationQueues &mutationQueues; @property(nonatomic, assign, getter=isStarted) BOOL started; @@ -134,13 +136,14 @@ - (ListenSequenceNumber)currentSequenceNumber { return _transactionRunner; } -- (id)mutationQueueForUser:(const User &)user { - id queue = _mutationQueues[user]; - if (!queue) { - queue = [[FSTMemoryMutationQueue alloc] initWithPersistence:self]; - _mutationQueues[user] = queue; +- (MemoryMutationQueue *)mutationQueueForUser:(const User &)user { + const std::unique_ptr &existing = _mutationQueues[user]; + if (!existing) { + _mutationQueues[user] = absl::make_unique(self); + return _mutationQueues[user].get(); + } else { + return existing.get(); } - return queue; } - (MemoryQueryCache *)queryCache { @@ -272,7 +275,7 @@ - (void)removeReference:(const DocumentKey &)key { - (BOOL)mutationQueuesContainKey:(const DocumentKey &)key { const MutationQueues &queues = [_persistence mutationQueues]; for (const auto &entry : queues) { - if ([entry.second containsKey:key]) { + if (entry.second->ContainsKey(key)) { return YES; } } @@ -310,7 +313,7 @@ - (size_t)byteSize { count += _persistence.remoteDocumentCache->CalculateByteSize(_serializer); const MutationQueues &queues = [_persistence mutationQueues]; for (const auto &entry : queues) { - count += [entry.second byteSizeWithSerializer:_serializer]; + count += entry.second->CalculateByteSize(_serializer); } return count; } @@ -389,7 +392,7 @@ - (void)startTransaction:(__unused absl::string_view)label { - (BOOL)mutationQueuesContainKey:(const DocumentKey &)key { const MutationQueues &queues = [_persistence mutationQueues]; for (const auto &entry : queues) { - if ([entry.second containsKey:key]) { + if (entry.second->ContainsKey(key)) { return YES; } } diff --git a/Firestore/Source/Local/FSTMutationQueue.h b/Firestore/Source/Local/FSTMutationQueue.h deleted file mode 100644 index 6540e745b20..00000000000 --- a/Firestore/Source/Local/FSTMutationQueue.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2017 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import - -#include "Firestore/core/src/firebase/firestore/local/mutation_queue.h" -#include "Firestore/core/src/firebase/firestore/model/document_key.h" -#include "Firestore/core/src/firebase/firestore/model/document_key_set.h" -#include "Firestore/core/src/firebase/firestore/model/types.h" - -@class FSTMutation; -@class FSTMutationBatch; -@class FSTQuery; -@class FIRTimestamp; - -NS_ASSUME_NONNULL_BEGIN - -#pragma mark - FSTMutationQueue - -/** A queue of mutations to apply to the remote store. */ -@protocol FSTMutationQueue - -/** - * Starts the mutation queue, performing any initial reads that might be required to establish - * invariants, etc. - */ -- (void)start; - -/** Returns YES if this queue contains no mutation batches. */ -- (BOOL)isEmpty; - -/** Acknowledges the given batch. */ -- (void)acknowledgeBatch:(FSTMutationBatch *)batch streamToken:(nullable NSData *)streamToken; - -/** Returns the current stream token for this mutation queue. */ -- (nullable NSData *)lastStreamToken; - -/** Sets the stream token for this mutation queue. */ -- (void)setLastStreamToken:(nullable NSData *)streamToken; - -/** Creates a new mutation batch and adds it to this mutation queue. */ -- (FSTMutationBatch *)addMutationBatchWithWriteTime:(FIRTimestamp *)localWriteTime - mutations:(NSArray *)mutations; - -/** Loads the mutation batch with the given batchID. */ -- (nullable FSTMutationBatch *)lookupMutationBatch:(firebase::firestore::model::BatchId)batchID; - -/** - * Gets the first unacknowledged mutation batch after the passed in batchId in the mutation queue - * or nil if empty. - * - * @param batchID The batch to search after, or kBatchIdUnknown for the first mutation in the - * queue. - * - * @return the next mutation or nil if there wasn't one. - */ -- (nullable FSTMutationBatch *)nextMutationBatchAfterBatchID: - (firebase::firestore::model::BatchId)batchID; - -/** Gets all mutation batches in the mutation queue. */ -// TODO(mikelehen): PERF: Current consumer only needs mutated keys; if we can provide that -// cheaply, we should replace this. -- (NSArray *)allMutationBatches; - -/** - * Finds all mutation batches that could @em possibly affect the given document key. Not all - * mutations in a batch will necessarily affect the document key, so when looping through the - * batch you'll need to check that the mutation itself matches the key. - * - * Note that because of this requirement implementations are free to return mutation batches that - * don't contain the document key at all if it's convenient. - */ -// TODO(mcg): This should really return an NSEnumerator -- (NSArray *)allMutationBatchesAffectingDocumentKey: - (const firebase::firestore::model::DocumentKey &)documentKey; - -/** - * Finds all mutation batches that could @em possibly affect the given document keys. Not all - * mutations in a batch will necessarily affect each key, so when looping through the batches you'll - * need to check that the mutation itself matches the key. - * - * Note that because of this requirement implementations are free to return mutation batches that - * don't contain any of the given document keys at all if it's convenient. - */ -// TODO(mcg): This should really return an NSEnumerator -- (NSArray *)allMutationBatchesAffectingDocumentKeys: - (const firebase::firestore::model::DocumentKeySet &)documentKeys; - -/** - * Finds all mutation batches that could affect the results for the given query. Not all - * mutations in a batch will necessarily affect the query, so when looping through the batch - * you'll need to check that the mutation itself matches the query. - * - * Note that because of this requirement implementations are free to return mutation batches that - * don't match the query at all if it's convenient. - * - * NOTE: A FSTPatchMutation does not need to include all fields in the query filter criteria in - * order to be a match (but any fields it does contain do need to match). - */ -// TODO(mikelehen): This should perhaps return an NSEnumerator, though I'm not sure we can avoid -// loading them all in memory. -- (NSArray *)allMutationBatchesAffectingQuery:(FSTQuery *)query; - -/** - * Removes the given mutation batch from the queue. This is useful in two circumstances: - * - * + Removing applied mutations from the head of the queue - * + Removing rejected mutations from anywhere in the queue - */ -- (void)removeMutationBatch:(FSTMutationBatch *)batch; - -/** Performs a consistency check, examining the mutation queue for any leaks, if possible. */ -- (void)performConsistencyCheck; - -// Visible for testing -- (firebase::firestore::local::MutationQueue *)mutationQueue; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Local/FSTPersistence.h b/Firestore/Source/Local/FSTPersistence.h index e44ee6500d6..961ad0dcbf7 100644 --- a/Firestore/Source/Local/FSTPersistence.h +++ b/Firestore/Source/Local/FSTPersistence.h @@ -17,6 +17,7 @@ #import #include "Firestore/core/src/firebase/firestore/auth/user.h" +#include "Firestore/core/src/firebase/firestore/local/mutation_queue.h" #include "Firestore/core/src/firebase/firestore/local/query_cache.h" #include "Firestore/core/src/firebase/firestore/local/reference_set.h" #include "Firestore/core/src/firebase/firestore/local/remote_document_cache.h" @@ -26,7 +27,6 @@ #include "Firestore/core/src/firebase/firestore/util/status.h" @class FSTQueryData; -@protocol FSTMutationQueue; @protocol FSTReferenceDelegate; struct FSTTransactionRunner; @@ -69,14 +69,15 @@ NS_ASSUME_NONNULL_BEGIN - (void)shutdown; /** - * Returns an FSTMutationQueue representing the persisted mutations for the given user. + * Returns a MutationQueue representing the persisted mutations for the given user. * *

Note: The implementation is free to return the same instance every time this is called for a * given user. In particular, the memory-backed implementation does this to emulate the persisted * implementation to the extent possible (e.g. in the case of uid switching from * sally=>jack=>sally, sally's mutation queue will be preserved). */ -- (id)mutationQueueForUser:(const firebase::firestore::auth::User &)user; +- (firebase::firestore::local::MutationQueue *)mutationQueueForUser: + (const firebase::firestore::auth::User &)user; /** Creates an FSTQueryCache representing the persisted cache of queries. */ - (firebase::firestore::local::QueryCache *)queryCache;