Skip to content

Commit 0b14a8c

Browse files
Make clearIndexedDbPersistence() work without enableIndexedDbPersistence() (#3373)
1 parent 4fc68ef commit 0b14a8c

File tree

8 files changed

+192
-134
lines changed

8 files changed

+192
-134
lines changed

.changeset/nice-deers-suffer.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ import { Code, FirestoreError } from '../../../src/util/error';
4545
import { Deferred } from '../../../src/util/promise';
4646
import { LruParams } from '../../../src/local/lru_garbage_collector';
4747
import { CACHE_SIZE_UNLIMITED } from '../../../src/api/database';
48-
import { DatabaseInfo } from '../../../src/core/database_info';
48+
import { DatabaseId, DatabaseInfo } from '../../../src/core/database_info';
49+
import {
50+
indexedDbStoragePrefix,
51+
indexedDbClearPersistence
52+
} from '../../../src/local/indexeddb_persistence';
4953

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

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

155-
const settings = this._getSettings();
156168
const deferred = new Deferred<void>();
157169
this._queue.enqueueAndForgetEvenAfterShutdown(async () => {
158170
try {
159-
const databaseInfo = this._makeDatabaseInfo(
160-
settings.host,
161-
settings.ssl,
162-
settings.experimentalForceLongPolling
163-
);
164-
await this._componentProvider.clearPersistence(databaseInfo);
171+
await delegate(this._databaseId, this._persistenceKey);
165172
deferred.resolve();
166173
} catch (e) {
167174
deferred.reject(e);
@@ -247,7 +254,11 @@ export function clearIndexedDbPersistence(
247254
firestore: firestore.FirebaseFirestore
248255
): Promise<void> {
249256
const firestoreImpl = cast(firestore, Firestore);
250-
return firestoreImpl._clearPersistence();
257+
return firestoreImpl._clearPersistence((databaseId, persistenceKey) => {
258+
return indexedDbClearPersistence(
259+
indexedDbStoragePrefix(databaseId, persistenceKey)
260+
);
261+
});
251262
}
252263

253264
export function waitForPendingWrites(

0 commit comments

Comments
 (0)