From b3050e42d842a4aef122efd277481c46bfa88dff Mon Sep 17 00:00:00 2001 From: zxu Date: Sat, 24 Mar 2018 11:06:32 -0400 Subject: port C++ `DocumentKey` to `Remote/*` (#965) * port C++ DocumentKey to Remote's * port C++ DocumentKey to Remote's * address changes * address changes * address changes --- Firestore/Source/Local/FSTLocalStore.mm | 46 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'Firestore/Source/Local/FSTLocalStore.mm') diff --git a/Firestore/Source/Local/FSTLocalStore.mm b/Firestore/Source/Local/FSTLocalStore.mm index 922f281..1bcc6d0 100644 --- a/Firestore/Source/Local/FSTLocalStore.mm +++ b/Firestore/Source/Local/FSTLocalStore.mm @@ -47,6 +47,7 @@ using firebase::firestore::auth::User; using firebase::firestore::model::DocumentKey; using firebase::firestore::core::TargetIdGenerator; +using firebase::firestore::model::DocumentKey; NS_ASSUME_NONNULL_BEGIN @@ -320,28 +321,29 @@ NS_ASSUME_NONNULL_BEGIN }]; // TODO(klimt): This could probably be an NSMutableDictionary. - __block FSTDocumentKeySet *changedDocKeys = [FSTDocumentKeySet keySet]; - [remoteEvent.documentUpdates - enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey *key, FSTMaybeDocument *doc, BOOL *stop) { - changedDocKeys = [changedDocKeys setByAddingObject:key]; - FSTMaybeDocument *existingDoc = [remoteDocuments entryForKey:key]; - // Make sure we don't apply an old document version to the remote cache, though we - // make an exception for [SnapshotVersion noVersion] which can happen for manufactured - // events (e.g. in the case of a limbo document resolution failing). - if (!existingDoc || [doc.version isEqual:[FSTSnapshotVersion noVersion]] || - [doc.version compare:existingDoc.version] != NSOrderedAscending) { - [remoteDocuments addEntry:doc]; - } else { - FSTLog( - @"FSTLocalStore Ignoring outdated watch update for %@. " - "Current version: %@ Watch version: %@", - key, existingDoc.version, doc.version); - } - - // The document might be garbage because it was unreferenced by everything. - // Make sure to mark it as garbage if it is... - [self.garbageCollector addPotentialGarbageKey:key]; - }]; + FSTDocumentKeySet *changedDocKeys = [FSTDocumentKeySet keySet]; + for (const auto &kv : remoteEvent.documentUpdates) { + const DocumentKey &key = kv.first; + FSTMaybeDocument *doc = kv.second; + changedDocKeys = [changedDocKeys setByAddingObject:key]; + FSTMaybeDocument *existingDoc = [remoteDocuments entryForKey:key]; + // Make sure we don't apply an old document version to the remote cache, though we + // make an exception for [SnapshotVersion noVersion] which can happen for manufactured + // events (e.g. in the case of a limbo document resolution failing). + if (!existingDoc || [doc.version isEqual:[FSTSnapshotVersion noVersion]] || + [doc.version compare:existingDoc.version] != NSOrderedAscending) { + [remoteDocuments addEntry:doc]; + } else { + FSTLog( + @"FSTLocalStore Ignoring outdated watch update for %s. " + "Current version: %@ Watch version: %@", + key.ToString().c_str(), existingDoc.version, doc.version); + } + + // The document might be garbage because it was unreferenced by everything. + // Make sure to mark it as garbage if it is... + [self.garbageCollector addPotentialGarbageKey:key]; + } // HACK: The only reason we allow omitting snapshot version is so we can synthesize remote events // when we get permission denied errors while trying to resolve the state of a locally cached -- cgit v1.2.3