Skip to content

Commit 8f9a674

Browse files
Meake clearPersistence() work without enablePersistence()
1 parent b18ed91 commit 8f9a674

File tree

7 files changed

+184
-135
lines changed

7 files changed

+184
-135
lines changed

packages/firestore/exp/src/api/database.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ import { Code, FirestoreError } from '../../../src/util/error';
4444
import { Deferred } from '../../../src/util/promise';
4545
import { LruParams } from '../../../src/local/lru_garbage_collector';
4646
import { CACHE_SIZE_UNLIMITED } from '../../../src/api/database';
47-
import { DatabaseInfo } from '../../../src/core/database_info';
47+
import { DatabaseId, DatabaseInfo } from '../../../src/core/database_info';
48+
import {
49+
buildStoragePrefix,
50+
clearPersistence
51+
} from '../../../src/local/indexeddb_persistence';
4852

4953
/**
5054
* The root reference to the Firestore database and the entry point for the
@@ -142,7 +146,16 @@ export class Firestore extends LiteFirestore
142146
return terminate(this);
143147
}
144148

145-
_clearPersistence(): Promise<void> {
149+
/**
150+
* Verifies that the client is not running and clears persistence by invoking
151+
* `clearPersistenceDelegate` on the async queue.
152+
*
153+
* @param delegate A function that clears the clients
154+
* backing storage.
155+
*/
156+
_clearPersistence(
157+
delegate: (databaseId: DatabaseId, persistenceKey: string) => Promise<void>
158+
): Promise<void> {
146159
if (this._deferredInitialization !== undefined && !this._terminated) {
147160
throw new FirestoreError(
148161
Code.FAILED_PRECONDITION,
@@ -151,16 +164,10 @@ export class Firestore extends LiteFirestore
151164
);
152165
}
153166

154-
const settings = this._getSettings();
155167
const deferred = new Deferred<void>();
156168
this._queue.enqueueAndForgetEvenAfterShutdown(async () => {
157169
try {
158-
const databaseInfo = this._makeDatabaseInfo(
159-
settings.host,
160-
settings.ssl,
161-
settings.experimentalForceLongPolling
162-
);
163-
await this._componentProvider.clearPersistence(databaseInfo);
170+
await delegate(this._databaseId, this._persistenceKey);
164171
deferred.resolve();
165172
} catch (e) {
166173
deferred.reject(e);
@@ -246,7 +253,9 @@ export function clearIndexedDbPersistence(
246253
firestore: firestore.FirebaseFirestore
247254
): Promise<void> {
248255
const firestoreImpl = cast(firestore, Firestore);
249-
return firestoreImpl._clearPersistence();
256+
return firestoreImpl._clearPersistence((databaseId, persistenceKey) => {
257+
return clearPersistence(buildStoragePrefix(databaseId, persistenceKey));
258+
});
250259
}
251260

252261
export function waitForPendingWrites(

0 commit comments

Comments
 (0)