@@ -166,6 +166,7 @@ export class SimpleDb {
166
166
private db ?: IDBDatabase ;
167
167
private databaseDeletedListener ?: DatabaseDeletedListener ;
168
168
private lastClosedDbVersion : number | null = null ;
169
+ private readonly logTag = `${ LOG_TAG } [${ generateUniqueDebugId ( ) } ]` ;
169
170
170
171
/** Deletes the specified database. */
171
172
static delete ( name : string ) : Promise < void > {
@@ -270,6 +271,7 @@ export class SimpleDb {
270
271
private readonly version : number ,
271
272
private readonly schemaConverter : SimpleDbSchemaConverter
272
273
) {
274
+ logDebug ( `${ this . logTag } created!` ) ;
273
275
debugAssert (
274
276
SimpleDb . isAvailable ( ) ,
275
277
'IndexedDB not supported in current environment.'
@@ -295,7 +297,8 @@ export class SimpleDb {
295
297
*/
296
298
async ensureDb ( action : string ) : Promise < IDBDatabase > {
297
299
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 ) ;
299
302
this . db = await new Promise < IDBDatabase > ( ( resolve , reject ) => {
300
303
// TODO(mikelehen): Investigate browser compatibility.
301
304
// https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
@@ -377,7 +380,7 @@ export class SimpleDb {
377
380
378
381
request . onupgradeneeded = ( event : IDBVersionChangeEvent ) => {
379
382
logDebug (
380
- LOG_TAG ,
383
+ this . logTag ,
381
384
'Database "' + this . name + '" requires upgrade from version:' ,
382
385
event . oldVersion
383
386
) ;
@@ -405,7 +408,7 @@ export class SimpleDb {
405
408
)
406
409
. next ( ( ) => {
407
410
logDebug (
408
- LOG_TAG ,
411
+ this . logTag ,
409
412
'Database upgrade to version ' + this . version + ' complete'
410
413
) ;
411
414
} ) ;
@@ -415,6 +418,7 @@ export class SimpleDb {
415
418
this . db . addEventListener (
416
419
'close' ,
417
420
event => {
421
+ logDebug ( `${ this . logTag } close callback` ) ;
418
422
const db = event . target as IDBDatabase ;
419
423
this . lastClosedDbVersion = db . version ;
420
424
} ,
@@ -460,6 +464,7 @@ export class SimpleDb {
460
464
objectStores : string [ ] ,
461
465
transactionFn : ( transaction : SimpleDbTransaction ) => PersistencePromise < T >
462
466
) : Promise < T > {
467
+ logDebug ( `${ this . logTag } runTransaction action=${ action } ` ) ;
463
468
const readonly = mode === 'readonly' ;
464
469
let attemptNumber = 0 ;
465
470
@@ -512,7 +517,7 @@ export class SimpleDb {
512
517
error . name !== 'FirebaseError' &&
513
518
attemptNumber < TRANSACTION_RETRY_COUNT ;
514
519
logDebug (
515
- LOG_TAG ,
520
+ this . logTag ,
516
521
'Transaction failed with error:' ,
517
522
error . message ,
518
523
'Retrying:' ,
@@ -529,6 +534,7 @@ export class SimpleDb {
529
534
}
530
535
531
536
close ( ) : void {
537
+ logDebug ( `${ this . logTag } close() called!` ) ;
532
538
if ( this . db ) {
533
539
this . db . close ( ) ;
534
540
}
0 commit comments