Skip to content

Commit 1bafdb4

Browse files
rsgowmanwilhuff
authored andcommitted
Fix FSTLocalDocumentsView to allow multiple mutations while offline (#644)
* Fix FSTLocalDocumentsView to allow multiple mutations while offline. Previously, only the last mutation would actually be visible.
1 parent 4cdd87a commit 1bafdb4

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

Firestore/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Unreleased (firestore-api-changes)
1+
# Unreleased
22
- [changed] Removed the includeMetadataChanges property in FIRDocumentListenOptions
33
to avoid confusion with the factory method of the same name.
44
- [changed] Added a commit method that takes no completion handler to FIRWriteBatch.
@@ -13,6 +13,8 @@
1313
`true` if the SDK loses its connection to the backend. A new event with
1414
`snapshot.metadata.isFromCache` set to false will be raised once the
1515
connection is restored and the query is in sync with the backend again.
16+
- [fixed] Multiple offline mutations now properly reflected in retrieved
17+
documents. Previously, only the last mutation would be visible. (#643)
1618

1719
# v0.9.4
1820
- [changed] Firestore no longer has a direct dependency on FirebaseAuth.

Firestore/Example/Tests/Integration/API/FIRQueryTests.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,27 @@ - (void)testQueriesFireFromCacheWhenOffline {
275275
[registration remove];
276276
}
277277

278+
- (void)testCanHaveMultipleMutationsWhileOffline {
279+
FIRCollectionReference *col = [self collectionRef];
280+
281+
// set a few docs to known values
282+
NSDictionary *initialDocs =
283+
@{ @"doc1" : @{@"key1" : @"value1"},
284+
@"doc2" : @{@"key2" : @"value2"} };
285+
[self writeAllDocuments:initialDocs toCollection:col];
286+
287+
// go offline for the rest of this test
288+
[self disableNetwork];
289+
290+
// apply *multiple* mutations while offline
291+
[[col documentWithPath:@"doc1"] setData:@{@"key1b" : @"value1b"}];
292+
[[col documentWithPath:@"doc2"] setData:@{@"key2b" : @"value2b"}];
293+
294+
FIRQuerySnapshot *result = [self readDocumentSetForRef:col];
295+
XCTAssertEqualObjects(FIRQuerySnapshotGetData(result), (@[
296+
@{@"key1b" : @"value1b"},
297+
@{@"key2b" : @"value2b"},
298+
]));
299+
}
300+
278301
@end

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818

1919
#import <FirebaseCore/FIRLogger.h>
2020
#import <FirebaseFirestore/FirebaseFirestore-umbrella.h>
21-
#import <Firestore/Source/Core/FSTFirestoreClient.h>
2221
#import <GRPCClient/GRPCCall+ChannelArg.h>
2322
#import <GRPCClient/GRPCCall+Tests.h>
2423

2524
#include "Firestore/core/src/firebase/firestore/util/autoid.h"
2625

2726
#import "Firestore/Source/API/FIRFirestore+Internal.h"
2827
#import "Firestore/Source/Auth/FSTEmptyCredentialsProvider.h"
28+
#import "Firestore/Source/Core/FSTFirestoreClient.h"
2929
#import "Firestore/Source/Local/FSTLevelDB.h"
3030
#import "Firestore/Source/Model/FSTDatabaseID.h"
3131
#import "Firestore/Source/Util/FSTDispatchQueue.h"

Firestore/Source/Local/FSTLocalDocumentsView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ - (FSTDocumentDictionary *)localDocuments:(FSTDocumentDictionary *)documents {
167167
BOOL *stop) {
168168
FSTMaybeDocument *mutatedDoc = [self localDocument:remoteDocument key:key];
169169
if ([mutatedDoc isKindOfClass:[FSTDeletedDocument class]]) {
170-
result = [documents dictionaryByRemovingObjectForKey:key];
170+
result = [result dictionaryByRemovingObjectForKey:key];
171171
} else if ([mutatedDoc isKindOfClass:[FSTDocument class]]) {
172-
result = [documents dictionaryBySettingObject:(FSTDocument *)mutatedDoc forKey:key];
172+
result = [result dictionaryBySettingObject:(FSTDocument *)mutatedDoc forKey:key];
173173
} else {
174174
FSTFail(@"Unknown document: %@", mutatedDoc);
175175
}

0 commit comments

Comments
 (0)