@@ -245,7 +245,10 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
245
245
. remoteDocumentKeys ( queryData . targetId )
246
246
. then ( remoteKeys => {
247
247
const view = new View ( query , remoteKeys ) ;
248
- const viewDocChanges = view . computeDocChanges ( docs ) ;
248
+ const viewDocChanges = view . computeDocChanges (
249
+ docs ,
250
+ SnapshotVersion . MIN
251
+ ) ;
249
252
const synthesizedTargetChange = TargetChange . createSynthesizedTargetChangeForCurrentChange (
250
253
queryData . targetId ,
251
254
current && this . onlineState !== OnlineState . Offline
@@ -349,7 +352,10 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
349
352
. then ( result => {
350
353
this . sharedClientState . addPendingMutation ( result . batchId ) ;
351
354
this . addMutationCallback ( result . batchId , userCallback ) ;
352
- return this . emitNewSnapsAndNotifyLocalStore ( result . changes ) ;
355
+ return this . emitNewSnapsAndNotifyLocalStore (
356
+ result . changes ,
357
+ SnapshotVersion . MIN
358
+ ) ;
353
359
} )
354
360
. then ( ( ) => {
355
361
return this . remoteStore . fillWritePipeline ( ) ;
@@ -459,7 +465,11 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
459
465
}
460
466
}
461
467
) ;
462
- return this . emitNewSnapsAndNotifyLocalStore ( changes , remoteEvent ) ;
468
+ return this . emitNewSnapsAndNotifyLocalStore (
469
+ changes ,
470
+ remoteEvent . snapshotVersion ,
471
+ remoteEvent
472
+ ) ;
463
473
} )
464
474
. catch ( err => this . ignoreIfPrimaryLeaseLoss ( err ) ) ;
465
475
}
@@ -505,7 +515,12 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
505
515
this . assertSubscribed ( 'rejectListens()' ) ;
506
516
507
517
// PORTING NOTE: Multi-tab only.
508
- this . sharedClientState . updateQueryState ( targetId , 'rejected' , err ) ;
518
+ this . sharedClientState . updateQueryState (
519
+ targetId ,
520
+ SnapshotVersion . MIN ,
521
+ 'rejected' ,
522
+ err
523
+ ) ;
509
524
510
525
const limboResolution = this . limboResolutionsByTarget [ targetId ] ;
511
526
const limboKey = limboResolution && limboResolution . key ;
@@ -527,7 +542,11 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
527
542
) ;
528
543
documentUpdates = documentUpdates . insert (
529
544
limboKey ,
530
- new NoDocument ( limboKey , SnapshotVersion . forDeletedDoc ( ) )
545
+ new NoDocument (
546
+ limboKey ,
547
+ SnapshotVersion . forDeletedDoc ( ) ,
548
+ SnapshotVersion . MIN
549
+ )
531
550
) ;
532
551
const resolvedLimboDocuments = documentKeySet ( ) . add ( limboKey ) ;
533
552
const event = new RemoteEvent (
@@ -552,6 +571,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
552
571
// PORTING NOTE: Multi-tab only
553
572
async applyBatchState (
554
573
batchId : BatchId ,
574
+ snapshotVersion : SnapshotVersion ,
555
575
batchState : MutationBatchState ,
556
576
error ?: FirestoreError
557
577
) : Promise < void > {
@@ -585,7 +605,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
585
605
fail ( `Unknown batchState: ${ batchState } ` ) ;
586
606
}
587
607
588
- await this . emitNewSnapsAndNotifyLocalStore ( documents ) ;
608
+ await this . emitNewSnapsAndNotifyLocalStore ( documents , snapshotVersion ) ;
589
609
}
590
610
591
611
applySuccessfulWrite (
@@ -604,7 +624,15 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
604
624
return this . localStore
605
625
. acknowledgeBatch ( mutationBatchResult )
606
626
. then ( changes => {
607
- return this . emitNewSnapsAndNotifyLocalStore ( changes ) ;
627
+ this . sharedClientState . updateMutationState (
628
+ batchId ,
629
+ mutationBatchResult . commitVersion ,
630
+ 'acknowledged'
631
+ ) ;
632
+ return this . emitNewSnapsAndNotifyLocalStore (
633
+ changes ,
634
+ mutationBatchResult . commitVersion
635
+ ) ;
608
636
} )
609
637
. catch ( err => this . ignoreIfPrimaryLeaseLoss ( err ) ) ;
610
638
}
@@ -621,8 +649,16 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
621
649
return this . localStore
622
650
. rejectBatch ( batchId )
623
651
. then ( changes => {
624
- this . sharedClientState . updateMutationState ( batchId , 'rejected' , error ) ;
625
- return this . emitNewSnapsAndNotifyLocalStore ( changes ) ;
652
+ this . sharedClientState . updateMutationState (
653
+ batchId ,
654
+ SnapshotVersion . MIN ,
655
+ 'rejected' ,
656
+ error
657
+ ) ;
658
+ return this . emitNewSnapsAndNotifyLocalStore (
659
+ changes ,
660
+ SnapshotVersion . MIN
661
+ ) ;
626
662
} )
627
663
. catch ( err => this . ignoreIfPrimaryLeaseLoss ( err ) ) ;
628
664
}
@@ -759,6 +795,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
759
795
760
796
private async emitNewSnapsAndNotifyLocalStore (
761
797
changes : MaybeDocumentMap ,
798
+ snapshotVersion : SnapshotVersion ,
762
799
remoteEvent ?: RemoteEvent
763
800
) : Promise < void > {
764
801
const newSnaps : ViewSnapshot [ ] = [ ] ;
@@ -769,15 +806,22 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
769
806
queriesProcessed . push (
770
807
Promise . resolve ( )
771
808
. then ( ( ) => {
772
- const viewDocChanges = queryView . view . computeDocChanges ( changes ) ;
809
+ const viewDocChanges = queryView . view . computeDocChanges (
810
+ changes ,
811
+ snapshotVersion
812
+ ) ;
773
813
if ( ! viewDocChanges . needsRefill ) {
774
814
return viewDocChanges ;
775
815
}
776
816
// The query has a limit and some docs were removed, so we need
777
817
// to re-run the query against the local store to make sure we
778
818
// didn't lose any good docs that had been past the limit.
779
819
return this . localStore . executeQuery ( queryView . query ) . then ( docs => {
780
- return queryView . view . computeDocChanges ( docs , viewDocChanges ) ;
820
+ return queryView . view . computeDocChanges (
821
+ docs ,
822
+ snapshotVersion ,
823
+ viewDocChanges
824
+ ) ;
781
825
} ) ;
782
826
} )
783
827
. then ( ( viewDocChanges : ViewDocumentChanges ) => {
@@ -796,6 +840,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
796
840
if ( this . isPrimary ) {
797
841
this . sharedClientState . updateQueryState (
798
842
queryView . targetId ,
843
+ snapshotVersion ,
799
844
viewChange . snapshot . fromCache ? 'not-current' : 'current'
800
845
) ;
801
846
}
@@ -860,7 +905,10 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
860
905
result . removedBatchIds ,
861
906
result . addedBatchIds
862
907
) ;
863
- await this . emitNewSnapsAndNotifyLocalStore ( result . affectedDocuments ) ;
908
+ await this . emitNewSnapsAndNotifyLocalStore (
909
+ result . affectedDocuments ,
910
+ SnapshotVersion . MIN
911
+ ) ;
864
912
}
865
913
866
914
await this . remoteStore . handleCredentialChange ( ) ;
@@ -973,6 +1021,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
973
1021
// PORTING NOTE: Multi-tab only
974
1022
async applyTargetState (
975
1023
targetId : TargetId ,
1024
+ snapshotVersion : SnapshotVersion ,
976
1025
state : QueryTargetState ,
977
1026
error ?: FirestoreError
978
1027
) : Promise < void > {
@@ -994,6 +1043,7 @@ export class SyncEngine implements RemoteSyncer, SharedClientStateSyncer {
994
1043
) ;
995
1044
return this . emitNewSnapsAndNotifyLocalStore (
996
1045
changes ,
1046
+ snapshotVersion ,
997
1047
synthesizedRemoteEvent
998
1048
) ;
999
1049
}
0 commit comments