@@ -61,9 +61,10 @@ import { LRU_MINIMUM_CACHE_SIZE_BYTES } from '../local/lru_garbage_collector_imp
61
61
import { debugAssert } from '../util/assert' ;
62
62
import { AsyncQueue } from '../util/async_queue' ;
63
63
import { AsyncQueueImpl } from '../util/async_queue_impl' ;
64
+ import { generateUniqueDebugId } from '../util/debug_uid' ;
64
65
import { Code , FirestoreError } from '../util/error' ;
65
66
import { cast } from '../util/input_validation' ;
66
- import { logWarn } from '../util/log' ;
67
+ import { logDebug , logWarn } from '../util/log' ;
67
68
import { Deferred } from '../util/promise' ;
68
69
69
70
import { LoadBundleTask } from './bundle' ;
@@ -94,6 +95,7 @@ export const CACHE_SIZE_UNLIMITED = LRU_COLLECTION_DISABLED;
94
95
* Do not call this constructor directly. Instead, use {@link (getFirestore:1)}.
95
96
*/
96
97
export class Firestore extends LiteFirestore {
98
+ readonly _debugId = `Firestore@${ generateUniqueDebugId ( ) } ` ;
97
99
/**
98
100
* Whether it's a {@link Firestore} or Firestore Lite instance.
99
101
*/
@@ -204,10 +206,20 @@ export function initializeFirestore(
204
206
void pingServer ( settings . host ) ;
205
207
}
206
208
207
- return provider . initialize ( {
209
+ const db = provider . initialize ( {
208
210
options : settings ,
209
211
instanceIdentifier : databaseId
210
212
} ) ;
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 ;
211
223
}
212
224
213
225
/**
@@ -269,6 +281,15 @@ export function getFirestore(
269
281
connectFirestoreEmulator ( db , ...emulator ) ;
270
282
}
271
283
}
284
+
285
+ logDebug (
286
+ `getFirestore(` +
287
+ `app.name=${ app . name ?? 'undefined' } , databaseId=${
288
+ databaseId ?? 'undefined'
289
+ } ` +
290
+ `) returns ${ db . _debugId } `
291
+ ) ;
292
+
272
293
return db ;
273
294
}
274
295
@@ -323,6 +344,7 @@ export function configureFirestore(firestore: Firestore): void {
323
344
firestore . _componentsProvider &&
324
345
buildComponentProvider ( firestore . _componentsProvider )
325
346
) ;
347
+ logDebug ( `${ firestore . _firestoreClient } created by ${ firestore . _debugId } ` ) ;
326
348
}
327
349
328
350
function buildComponentProvider ( componentsProvider : {
@@ -500,6 +522,8 @@ export function clearIndexedDbPersistence(firestore: Firestore): Promise<void> {
500
522
) ;
501
523
}
502
524
525
+ logDebug ( firestore . _debugId , 'clearIndexedDbPersistence()' ) ;
526
+
503
527
const deferred = new Deferred < void > ( ) ;
504
528
firestore . _queue . enqueueAndForgetEvenWhileRestricted ( async ( ) => {
505
529
try {
@@ -531,6 +555,7 @@ export function clearIndexedDbPersistence(firestore: Firestore): Promise<void> {
531
555
* acknowledged by the backend.
532
556
*/
533
557
export function waitForPendingWrites ( firestore : Firestore ) : Promise < void > {
558
+ logDebug ( firestore . _debugId , 'waitForPendingWrites()' ) ;
534
559
firestore = cast ( firestore , Firestore ) ;
535
560
const client = ensureFirestoreConfigured ( firestore ) ;
536
561
return firestoreClientWaitForPendingWrites ( client ) ;
@@ -543,6 +568,7 @@ export function waitForPendingWrites(firestore: Firestore): Promise<void> {
543
568
* @returns A `Promise` that is resolved once the network has been enabled.
544
569
*/
545
570
export function enableNetwork ( firestore : Firestore ) : Promise < void > {
571
+ logDebug ( firestore . _debugId , 'enableNetwork()' ) ;
546
572
firestore = cast ( firestore , Firestore ) ;
547
573
const client = ensureFirestoreConfigured ( firestore ) ;
548
574
return firestoreClientEnableNetwork ( client ) ;
@@ -557,6 +583,7 @@ export function enableNetwork(firestore: Firestore): Promise<void> {
557
583
* @returns A `Promise` that is resolved once the network has been disabled.
558
584
*/
559
585
export function disableNetwork ( firestore : Firestore ) : Promise < void > {
586
+ logDebug ( firestore . _debugId , 'disableNetwork()' ) ;
560
587
firestore = cast ( firestore , Firestore ) ;
561
588
const client = ensureFirestoreConfigured ( firestore ) ;
562
589
return firestoreClientDisableNetwork ( client ) ;
@@ -585,6 +612,7 @@ export function disableNetwork(firestore: Firestore): Promise<void> {
585
612
* terminated.
586
613
*/
587
614
export function terminate ( firestore : Firestore ) : Promise < void > {
615
+ logDebug ( firestore . _debugId , 'terminate()' ) ;
588
616
_removeServiceInstance (
589
617
firestore . app ,
590
618
'firestore' ,
@@ -608,6 +636,7 @@ export function loadBundle(
608
636
firestore : Firestore ,
609
637
bundleData : ReadableStream < Uint8Array > | ArrayBuffer | string
610
638
) : LoadBundleTask {
639
+ logDebug ( firestore . _debugId , 'loadBundle()' ) ;
611
640
firestore = cast ( firestore , Firestore ) ;
612
641
const client = ensureFirestoreConfigured ( firestore ) ;
613
642
const resultTask = new LoadBundleTask ( ) ;
@@ -636,6 +665,7 @@ export function namedQuery(
636
665
firestore : Firestore ,
637
666
name : string
638
667
) : Promise < Query | null > {
668
+ logDebug ( firestore . _debugId , 'namedQuery() name:' , name ) ;
639
669
firestore = cast ( firestore , Firestore ) ;
640
670
const client = ensureFirestoreConfigured ( firestore ) ;
641
671
return firestoreClientGetNamedQuery ( client , name ) . then ( namedQuery => {
0 commit comments