@@ -61,9 +61,10 @@ import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../local/lru_garbage_collector_imp
6161import { debugAssert } from '../util/assert' ;
6262import { AsyncQueue } from '../util/async_queue' ;
6363import { AsyncQueueImpl } from '../util/async_queue_impl' ;
64+ import { generateUniqueDebugId } from '../util/debug_uid' ;
6465import { Code , FirestoreError } from '../util/error' ;
6566import { cast } from '../util/input_validation' ;
66- import { logWarn } from '../util/log' ;
67+ import { logDebug , logWarn } from '../util/log' ;
6768import { Deferred } from '../util/promise' ;
6869
6970import { LoadBundleTask } from './bundle' ;
@@ -94,6 +95,7 @@ export const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED;
9495 * Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
9596 */
9697export class Firestore extends LiteFirestore {
98+ readonly _debugId = `Firestore@${ generateUniqueDebugId ( ) } ` ;
9799 /**
98100 * Whether it's a {@link Firestore} or Firestore Lite instance.
99101 */
@@ -204,10 +206,20 @@ export function initializeFirestore(
204206 void pingServer ( settings . host ) ;
205207 }
206208
207- return provider . initialize ( {
209+ const db = provider . initialize ( {
208210 options : settings ,
209211 instanceIdentifier : databaseId
210212 } ) ;
213+
214+ logDebug (
215+ `initializeFirestore(` +
216+ `app.name=${ app . name ?? 'undefined' } , databaseId=${
217+ databaseId ?? 'undefined'
218+ } ` +
219+ `) returns ${ db . _debugId } `
220+ ) ;
221+
222+ return db ;
211223}
212224
213225/**
@@ -269,6 +281,15 @@ export function getFirestore(
269281 connectFirestoreEmulator ( db , ...emulator ) ;
270282 }
271283 }
284+
285+ logDebug (
286+ `getFirestore(` +
287+ `app.name=${ app . name ?? 'undefined' } , databaseId=${
288+ databaseId ?? 'undefined'
289+ } ` +
290+ `) returns ${ db . _debugId } `
291+ ) ;
292+
272293 return db ;
273294}
274295
@@ -323,6 +344,7 @@ export function configureFirestore(firestore: Firestore): void {
323344 firestore . _componentsProvider &&
324345 buildComponentProvider ( firestore . _componentsProvider )
325346 ) ;
347+ logDebug ( `${ firestore . _firestoreClient } created by ${ firestore . _debugId } ` ) ;
326348}
327349
328350function buildComponentProvider ( componentsProvider : {
@@ -500,6 +522,8 @@ export function clearIndexedDbPersistence(firestore: Firestore): Promise<void> {
500522 ) ;
501523 }
502524
525+ logDebug ( firestore . _debugId , 'clearIndexedDbPersistence()' ) ;
526+
503527 const deferred = new Deferred < void > ( ) ;
504528 firestore . _queue . enqueueAndForgetEvenWhileRestricted ( async ( ) => {
505529 try {
@@ -531,6 +555,7 @@ export function clearIndexedDbPersistence(firestore: Firestore): Promise<void> {
531555 * acknowledged by the backend.
532556 */
533557export function waitForPendingWrites ( firestore : Firestore ) : Promise < void > {
558+ logDebug ( firestore . _debugId , 'waitForPendingWrites()' ) ;
534559 firestore = cast ( firestore , Firestore ) ;
535560 const client = ensureFirestoreConfigured ( firestore ) ;
536561 return firestoreClientWaitForPendingWrites ( client ) ;
@@ -543,6 +568,7 @@ export function waitForPendingWrites(firestore: Firestore): Promise<void> {
543568 * @returns A `Promise` that is resolved once the network has been enabled.
544569 */
545570export function enableNetwork ( firestore : Firestore ) : Promise < void > {
571+ logDebug ( firestore . _debugId , 'enableNetwork()' ) ;
546572 firestore = cast ( firestore , Firestore ) ;
547573 const client = ensureFirestoreConfigured ( firestore ) ;
548574 return firestoreClientEnableNetwork ( client ) ;
@@ -557,6 +583,7 @@ export function enableNetwork(firestore: Firestore): Promise<void> {
557583 * @returns A `Promise` that is resolved once the network has been disabled.
558584 */
559585export function disableNetwork ( firestore : Firestore ) : Promise < void > {
586+ logDebug ( firestore . _debugId , 'disableNetwork()' ) ;
560587 firestore = cast ( firestore , Firestore ) ;
561588 const client = ensureFirestoreConfigured ( firestore ) ;
562589 return firestoreClientDisableNetwork ( client ) ;
@@ -585,6 +612,7 @@ export function disableNetwork(firestore: Firestore): Promise<void> {
585612 * terminated.
586613 */
587614export function terminate ( firestore : Firestore ) : Promise < void > {
615+ logDebug ( firestore . _debugId , 'terminate()' ) ;
588616 _removeServiceInstance (
589617 firestore . app ,
590618 'firestore' ,
@@ -608,6 +636,7 @@ export function loadBundle(
608636 firestore : Firestore ,
609637 bundleData : ReadableStream < Uint8Array > | ArrayBuffer | string
610638) : LoadBundleTask {
639+ logDebug ( firestore . _debugId , 'loadBundle()' ) ;
611640 firestore = cast ( firestore , Firestore ) ;
612641 const client = ensureFirestoreConfigured ( firestore ) ;
613642 const resultTask = new LoadBundleTask ( ) ;
@@ -636,6 +665,7 @@ export function namedQuery(
636665 firestore : Firestore ,
637666 name : string
638667) : Promise < Query | null > {
668+ logDebug ( firestore . _debugId , 'namedQuery() name:' , name ) ;
639669 firestore = cast ( firestore , Firestore ) ;
640670 const client = ensureFirestoreConfigured ( firestore ) ;
641671 return firestoreClientGetNamedQuery ( client , name ) . then ( namedQuery => {
0 commit comments