-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make clearIndexedDbPersistence() work without enableIndexedDbPersistence() #3373
Changes from 2 commits
ddddda8
e0a69b8
76e3c6f
9000e06
0845047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,11 @@ import { Code, FirestoreError } from '../../../src/util/error'; | |
import { Deferred } from '../../../src/util/promise'; | ||
import { LruParams } from '../../../src/local/lru_garbage_collector'; | ||
import { CACHE_SIZE_UNLIMITED } from '../../../src/api/database'; | ||
import { DatabaseInfo } from '../../../src/core/database_info'; | ||
import { DatabaseId, DatabaseInfo } from '../../../src/core/database_info'; | ||
import { | ||
buildStoragePrefix, | ||
clearPersistence | ||
} from '../../../src/local/indexeddb_persistence'; | ||
|
||
/** | ||
* The root reference to the Firestore database and the entry point for the | ||
|
@@ -143,7 +147,16 @@ export class Firestore extends LiteFirestore | |
return terminate(this); | ||
} | ||
|
||
_clearPersistence(): Promise<void> { | ||
/** | ||
* Verifies that the client is not running and clears persistence by invoking | ||
* `delegate` on the async queue. | ||
* | ||
* @param delegate A function that clears the clients | ||
* backing storage. | ||
*/ | ||
_clearPersistence( | ||
delegate: (databaseId: DatabaseId, persistenceKey: string) => Promise<void> | ||
): Promise<void> { | ||
if (this._deferredInitialization !== undefined && !this._terminated) { | ||
throw new FirestoreError( | ||
Code.FAILED_PRECONDITION, | ||
|
@@ -152,16 +165,10 @@ export class Firestore extends LiteFirestore | |
); | ||
} | ||
|
||
const settings = this._getSettings(); | ||
const deferred = new Deferred<void>(); | ||
this._queue.enqueueAndForgetEvenAfterShutdown(async () => { | ||
try { | ||
const databaseInfo = this._makeDatabaseInfo( | ||
settings.host, | ||
settings.ssl, | ||
settings.experimentalForceLongPolling | ||
); | ||
await this._componentProvider.clearPersistence(databaseInfo); | ||
await delegate(this._databaseId, this._persistenceKey); | ||
deferred.resolve(); | ||
} catch (e) { | ||
deferred.reject(e); | ||
|
@@ -247,7 +254,9 @@ export function clearIndexedDbPersistence( | |
firestore: firestore.FirebaseFirestore | ||
): Promise<void> { | ||
const firestoreImpl = cast(firestore, Firestore); | ||
return firestoreImpl._clearPersistence(); | ||
return firestoreImpl._clearPersistence((databaseId, persistenceKey) => { | ||
return clearPersistence(buildStoragePrefix(databaseId, persistenceKey)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code reads as if it's circular unless you pay careful attention. If I realize this is getting at that type-operation naming discussion we started earlier so feel free to defer if you must, but I think it's really hurting the ability to understand what's going on here while reading the code directly. Sure you can go look at the imports but that breaks flow. Reading code is hard enough and we should strive to make it easy to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I stumbled across this earlier too, but didn't act upon my confusion. I think a minimum bar for code quality should be that at the very least the person writing it shouldn't be confused... Renamed to |
||
}); | ||
} | ||
|
||
export function waitForPendingWrites( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes seem unrelated. Revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. I actually tried to remove them earlier, but the pre commit hook brought them back in. I had to disable the precommit hook for this commit.