@@ -166,6 +166,7 @@ export class SimpleDb {
166166 private db ?: IDBDatabase ;
167167 private databaseDeletedListener ?: DatabaseDeletedListener ;
168168 private lastClosedDbVersion : number | null = null ;
169+ private readonly logTag = `${ LOG_TAG } [${ generateUniqueDebugId ( ) } ]` ;
169170
170171 /** Deletes the specified database. */
171172 static delete ( name : string ) : Promise < void > {
@@ -270,6 +271,7 @@ export class SimpleDb {
270271 private readonly version : number ,
271272 private readonly schemaConverter : SimpleDbSchemaConverter
272273 ) {
274+ logDebug ( `${ this . logTag } created!` ) ;
273275 debugAssert (
274276 SimpleDb . isAvailable ( ) ,
275277 'IndexedDB not supported in current environment.'
@@ -295,7 +297,8 @@ export class SimpleDb {
295297 */
296298 async ensureDb ( action : string ) : Promise < IDBDatabase > {
297299 if ( ! this . db ) {
298- logDebug ( LOG_TAG , 'Opening database:' , this . name ) ;
300+ console . trace ( "zzyzx SimpleDb.ensureDb() is opening a new database connection" ) ;
301+ logDebug ( this . logTag , 'Opening database:' , this . name ) ;
299302 this . db = await new Promise < IDBDatabase > ( ( resolve , reject ) => {
300303 // TODO(mikelehen): Investigate browser compatibility.
301304 // https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
@@ -377,7 +380,7 @@ export class SimpleDb {
377380
378381 request . onupgradeneeded = ( event : IDBVersionChangeEvent ) => {
379382 logDebug (
380- LOG_TAG ,
383+ this . logTag ,
381384 'Database "' + this . name + '" requires upgrade from version:' ,
382385 event . oldVersion
383386 ) ;
@@ -405,7 +408,7 @@ export class SimpleDb {
405408 )
406409 . next ( ( ) => {
407410 logDebug (
408- LOG_TAG ,
411+ this . logTag ,
409412 'Database upgrade to version ' + this . version + ' complete'
410413 ) ;
411414 } ) ;
@@ -415,6 +418,7 @@ export class SimpleDb {
415418 this . db . addEventListener (
416419 'close' ,
417420 event => {
421+ logDebug ( `${ this . logTag } close callback` ) ;
418422 const db = event . target as IDBDatabase ;
419423 this . lastClosedDbVersion = db . version ;
420424 } ,
@@ -460,6 +464,7 @@ export class SimpleDb {
460464 objectStores : string [ ] ,
461465 transactionFn : ( transaction : SimpleDbTransaction ) => PersistencePromise < T >
462466 ) : Promise < T > {
467+ logDebug ( `${ this . logTag } runTransaction action=${ action } ` ) ;
463468 const readonly = mode === 'readonly' ;
464469 let attemptNumber = 0 ;
465470
@@ -512,7 +517,7 @@ export class SimpleDb {
512517 error . name !== 'FirebaseError' &&
513518 attemptNumber < TRANSACTION_RETRY_COUNT ;
514519 logDebug (
515- LOG_TAG ,
520+ this . logTag ,
516521 'Transaction failed with error:' ,
517522 error . message ,
518523 'Retrying:' ,
@@ -529,6 +534,7 @@ export class SimpleDb {
529534 }
530535
531536 close ( ) : void {
537+ logDebug ( `${ this . logTag } close() called!` ) ;
532538 if ( this . db ) {
533539 this . db . close ( ) ;
534540 }
0 commit comments