File tree Expand file tree Collapse file tree 5 files changed +34
-20
lines changed Expand file tree Collapse file tree 5 files changed +34
-20
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
+ - [ feature] Added ` clearPersistence() ` , which clears the persistent storage
3
+ including pending writes and cached documents. This is intended to help
4
+ write reliable tests (https://github.com/firebase/firebase-js-sdk/issues/449 ).
2
5
3
6
# 1.3.2
4
7
- [ fixed] Firestore should now recover its connection to the server more
Original file line number Diff line number Diff line change @@ -64,22 +64,6 @@ NS_ASSUME_NONNULL_BEGIN
64
64
- (void )shutdownWithCompletion : (nullable void (^)(NSError *_Nullable error))completion
65
65
NS_SWIFT_NAME(shutdown(completion:));
66
66
67
- /* *
68
- * Clears the persistent storage. This includes pending writes and cached documents.
69
- *
70
- * Must be called while the firestore instance is not started (after the app is shutdown or when
71
- * the app is first initialized). On startup, this method must be called before other methods
72
- * (other than `FIRFirestore.settings`). If the firestore instance is still running, the function
73
- * will complete with an error code of `FailedPrecondition`.
74
- *
75
- * Note: `clearPersistence(completion:)` is primarily intended to help write reliable tests that
76
- * use Firestore. It uses the most efficient mechanism possible for dropping existing data but
77
- * does not attempt to securely overwrite or otherwise make cached data unrecoverable. For
78
- * applications that are sensitive to the disclosure of cache data in between user sessions we
79
- * strongly recommend not to enable persistence in the first place.
80
- */
81
- - (void )clearPersistenceWithCompletion : (nullable void (^)(NSError *_Nullable error))completion;
82
-
83
67
- (const std::shared_ptr<util::AsyncQueue> &)workerQueue ;
84
68
85
69
@property (nonatomic , assign , readonly ) std::shared_ptr<api::Firestore> wrapped;
Original file line number Diff line number Diff line change @@ -267,6 +267,10 @@ - (void)disableNetworkWithCompletion:(nullable void (^)(NSError *_Nullable))comp
267
267
_firestore->DisableNetwork (util::MakeCallback (completion));
268
268
}
269
269
270
+ - (void )clearPersistenceWithCompletion : (nullable void (^)(NSError *_Nullable error))completion {
271
+ _firestore->ClearPersistence (util::MakeCallback (completion));
272
+ }
273
+
270
274
@end
271
275
272
276
@implementation FIRFirestore (Internal)
@@ -287,10 +291,6 @@ + (BOOL)isLoggingEnabled {
287
291
return util::LogIsLoggable (util::kLogLevelDebug );
288
292
}
289
293
290
- - (void )clearPersistenceWithCompletion : (nullable void (^)(NSError *_Nullable error))completion {
291
- _firestore->ClearPersistence (util::MakeCallback (completion));
292
- }
293
-
294
294
+ (FIRFirestore *)recoverFromFirestore : (std::shared_ptr<Firestore>)firestore {
295
295
return (__bridge FIRFirestore *)firestore->extension ();
296
296
}
Original file line number Diff line number Diff line change @@ -176,6 +176,22 @@ NS_SWIFT_NAME(Firestore)
176
176
*/
177
177
- (void )disableNetworkWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
178
178
179
+ /* *
180
+ * Clears the persistent storage. This includes pending writes and cached documents.
181
+ *
182
+ * Must be called while the firestore instance is not started (after the app is shutdown or when
183
+ * the app is first initialized). On startup, this method must be called before other methods
184
+ * (other than `FIRFirestore.settings`). If the firestore instance is still running, the function
185
+ * will complete with an error code of `FailedPrecondition`.
186
+ *
187
+ * Note: `clearPersistence(completion:)` is primarily intended to help write reliable tests that
188
+ * use Firestore. It uses the most efficient mechanism possible for dropping existing data but
189
+ * does not attempt to securely overwrite or otherwise make cached data unrecoverable. For
190
+ * applications that are sensitive to the disclosure of cache data in between user sessions we
191
+ * strongly recommend not to enable persistence in the first place.
192
+ */
193
+ - (void )clearPersistenceWithCompletion:(nullable void (^)(NSError *_Nullable error))completion;
194
+
179
195
@end
180
196
181
197
NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change @@ -52,6 +52,8 @@ func main() {
52
52
53
53
enableDisableNetwork ( database: db)
54
54
55
+ clearPersistence ( database: db)
56
+
55
57
types ( )
56
58
}
57
59
@@ -174,6 +176,15 @@ func enableDisableNetwork(database db: Firestore) {
174
176
}
175
177
}
176
178
179
+ func clearPersistence( database db: Firestore ) {
180
+ db. clearPersistence { error in
181
+ if let e = error {
182
+ print ( " Uh oh! \( e) " )
183
+ return
184
+ }
185
+ }
186
+ }
187
+
177
188
func writeDocuments( at docRef: DocumentReference , database db: Firestore ) {
178
189
var batch : WriteBatch
179
190
You can’t perform that action at this time.
0 commit comments