@@ -35,26 +35,19 @@ import {
35
35
} from './indexeddb_schema' ;
36
36
import { LocalSerializer } from './local_serializer' ;
37
37
import { MutationQueue } from './mutation_queue' ;
38
- < < < << << HEAD
39
38
import {
40
39
Persistence ,
41
40
PersistenceTransaction ,
42
41
PrimaryStateListener
43
42
} from './persistence' ;
44
- === === =
45
- import { Persistence , PersistenceTransaction } from './persistence' ;
46
- >>> >>> > master
47
43
import { PersistencePromise } from './persistence_promise' ;
48
44
import { QueryCache } from './query_cache' ;
49
45
import { RemoteDocumentCache } from './remote_document_cache' ;
50
46
import { SimpleDb , SimpleDbStore , SimpleDbTransaction } from './simple_db' ;
51
- < < < << << HEAD
52
47
import { Platform } from '../platform/platform' ;
53
48
import { AsyncQueue , TimerId } from '../util/async_queue' ;
54
49
import { ClientId } from './shared_client_state' ;
55
50
import { CancelablePromise } from '../util/promise' ;
56
- === === =
57
- >>> >>> > master
58
51
59
52
const LOG_TAG = 'IndexedDbPersistence' ;
60
53
@@ -86,17 +79,15 @@ const UNSUPPORTED_PLATFORM_ERROR_MSG =
86
79
' IndexedDB or is known to have an incomplete implementation. Offline' +
87
80
' persistence has been disabled.' ;
88
81
89
- < < < << << HEAD
90
82
// The format of the LocalStorage key that stores zombied client is:
91
83
// firestore_zombie_<persistence_prefix>_<instance_key>
92
84
const ZOMBIED_CLIENTS_KEY_PREFIX = 'firestore_zombie' ;
93
- === === =
85
+
94
86
export class IndexedDbTransaction extends PersistenceTransaction {
95
87
constructor ( readonly simpleDbTransaction : SimpleDbTransaction ) {
96
88
super ( ) ;
97
89
}
98
90
}
99
- >>> >>> > master
100
91
101
92
/**
102
93
* An IndexedDB-backed instance of Persistence. Data is stored persistently
@@ -494,14 +485,10 @@ export class IndexedDbPersistence implements Persistence {
494
485
495
486
runTransaction < T > (
496
487
action : string ,
497
- < < < << << HEAD
498
488
requirePrimaryLease : boolean ,
499
489
transactionOperation : (
500
- transaction : PersistenceTransaction
490
+ transaction : IndexedDbTransaction
501
491
) => PersistencePromise < T >
502
- = === ===
503
- operation : ( transaction : IndexedDbTransaction ) => PersistencePromise < T >
504
- > > >>> >> master
505
492
) : Promise < T > {
506
493
// TODO(multitab): Consider removing `requirePrimaryLease` and exposing
507
494
// three different write modes (readonly, readwrite, readwrite_primary).
@@ -513,52 +500,47 @@ export class IndexedDbPersistence implements Persistence {
513
500
514
501
// Do all transactions as readwrite against all object stores, since we
515
502
// are the only reader/writer.
516
- << << << < HEAD
517
- return this . simpleDb . runTransaction ( 'readwrite' , ALL_STORES , txn => {
518
- if ( requirePrimaryLease ) {
519
- // While we merely verify that we have (or can acquire) the lease
520
- // immediately, we wait to extend the primary lease until after
521
- // executing transactionOperation(). This ensures that even if the
522
- // transactionOperation takes a long time, we'll use a recent
523
- // leaseTimestampMs in the extended (or newly acquired) lease.
524
- return this . canActAsPrimary ( txn )
525
- . next ( canActAsPrimary => {
526
- if ( ! canActAsPrimary ) {
527
- // TODO(multitab): Handle this gracefully and transition back to
528
- // secondary state.
529
- log . error (
530
- `Failed to obtain primary lease for action '${ action } '.`
531
- ) ;
532
- this . isPrimary = false ;
533
- this . queue . enqueue ( ( ) => this . primaryStateListener ( false ) ) ;
534
- throw new FirestoreError (
535
- Code . FAILED_PRECONDITION ,
536
- PRIMARY_LEASE_LOST_ERROR_MSG
537
- ) ;
538
- }
539
- return transactionOperation ( txn ) ;
540
- } )
541
- . next ( result => {
542
- return this . acquireOrExtendPrimaryLease ( txn ) . next ( ( ) => result ) ;
543
- } ) ;
544
- } else {
545
- return this . verifyAllowTabSynchronization ( txn ) . next ( ( ) =>
546
- transactionOperation ( txn )
547
- ) ;
548
- }
549
- } ) ;
550
- === = ===
551
503
return this . simpleDb . runTransaction (
552
504
'readwrite' ,
553
505
ALL_STORES ,
554
506
simpleDbTxn => {
555
- // Verify that we still have the owner lease as part of every transaction.
556
- return this . ensureOwnerLease ( simpleDbTxn ) . next ( ( ) =>
557
- operation ( new IndexedDbTransaction ( simpleDbTxn ) )
558
- ) ;
507
+ if ( requirePrimaryLease ) {
508
+ // While we merely verify that we have (or can acquire) the lease
509
+ // immediately, we wait to extend the primary lease until after
510
+ // executing transactionOperation(). This ensures that even if the
511
+ // transactionOperation takes a long time, we'll use a recent
512
+ // leaseTimestampMs in the extended (or newly acquired) lease.
513
+ return this . canActAsPrimary ( simpleDbTxn )
514
+ . next ( canActAsPrimary => {
515
+ if ( ! canActAsPrimary ) {
516
+ // TODO(multitab): Handle this gracefully and transition back to
517
+ // secondary state.
518
+ log . error (
519
+ `Failed to obtain primary lease for action '${ action } '.`
520
+ ) ;
521
+ this . isPrimary = false ;
522
+ this . queue . enqueue ( ( ) => this . primaryStateListener ( false ) ) ;
523
+ throw new FirestoreError (
524
+ Code . FAILED_PRECONDITION ,
525
+ PRIMARY_LEASE_LOST_ERROR_MSG
526
+ ) ;
527
+ }
528
+ return transactionOperation (
529
+ new IndexedDbTransaction ( simpleDbTxn )
530
+ ) ;
531
+ } )
532
+ . next ( result => {
533
+ return this . acquireOrExtendPrimaryLease ( simpleDbTxn ) . next (
534
+ ( ) => result
535
+ ) ;
536
+ } ) ;
537
+ } else {
538
+ return this . verifyAllowTabSynchronization ( simpleDbTxn ) . next ( ( ) =>
539
+ transactionOperation ( new IndexedDbTransaction ( simpleDbTxn ) )
540
+ ) ;
541
+ }
559
542
}
560
543
) ;
561
- >>> > >>> master
562
544
}
563
545
564
546
/**
@@ -659,7 +641,6 @@ export class IndexedDbPersistence implements Persistence {
659
641
return true ;
660
642
}
661
643
662
- << < < < << HEAD
663
644
private attachVisibilityHandler ( ) : void {
664
645
if (
665
646
this . document !== null &&
@@ -671,27 +652,6 @@ export class IndexedDbPersistence implements Persistence {
671
652
return this . updateClientMetadataAndTryBecomePrimary ( ) ;
672
653
} ) ;
673
654
} ;
674
- === = ===
675
- /**
676
- * Schedules a recurring timer to update the owner lease timestamp to prevent
677
- * other tabs from taking the lease.
678
- */
679
- private scheduleOwnerLeaseRefreshes ( ) : void {
680
- // NOTE: This doesn't need to be scheduled on the async queue and doing so
681
- // would increase the chances of us not refreshing on time if the queue is
682
- // backed up for some reason.
683
- this. ownerLeaseRefreshHandle = setInterval ( ( ) => {
684
- const txResult = this . simpleDb . runTransaction (
685
- 'readwrite' ,
686
- ALL_STORES ,
687
- txn => {
688
- // NOTE: We don't need to validate the current owner contents, since
689
- // runTransaction does that automatically.
690
- const store = txn . store < DbOwnerKey , DbOwner > ( DbOwner . store ) ;
691
- return store . put ( 'owner' , new DbOwner ( this . ownerId , Date . now ( ) ) ) ;
692
- }
693
- ) ;
694
- > >>> >>> master
695
655
696
656
this . document . addEventListener (
697
657
'visibilitychange' ,
0 commit comments