@@ -555,7 +555,7 @@ private DocumentChangeResult populateDocumentChanges(
555
555
* have to be too frequent.
556
556
*/
557
557
private static boolean shouldPersistTargetData (
558
- TargetData oldTargetData , TargetData newTargetData , TargetChange change ) {
558
+ TargetData oldTargetData , TargetData newTargetData , @ Nullable TargetChange change ) {
559
559
// Always persist query data if we don't already have a resume token.
560
560
if (oldTargetData .getResumeToken ().isEmpty ()) return true ;
561
561
@@ -568,10 +568,20 @@ private static boolean shouldPersistTargetData(
568
568
long timeDelta = newSeconds - oldSeconds ;
569
569
if (timeDelta >= RESUME_TOKEN_MAX_AGE_SECONDS ) return true ;
570
570
571
+ // Update the target cache if sufficient time has passed since the last
572
+ // LastLimboFreeSnapshotVersion
573
+ long newLimboFreeSeconds =
574
+ newTargetData .getLastLimboFreeSnapshotVersion ().getTimestamp ().getSeconds ();
575
+ long oldLimboFreeSeconds =
576
+ oldTargetData .getLastLimboFreeSnapshotVersion ().getTimestamp ().getSeconds ();
577
+ long limboFreeTimeDelta = newLimboFreeSeconds - oldLimboFreeSeconds ;
578
+ if (limboFreeTimeDelta >= RESUME_TOKEN_MAX_AGE_SECONDS ) return true ;
579
+
571
580
// Otherwise if the only thing that has changed about a target is its resume token it's not
572
581
// worth persisting. Note that the RemoteStore keeps an in-memory view of the currently active
573
582
// targets which includes the current resume token, so stream failure or user changes will still
574
583
// use an up-to-date resume token regardless of what we do here.
584
+ if (change == null ) return false ;
575
585
int changes =
576
586
change .getAddedDocuments ().size ()
577
587
+ change .getModifiedDocuments ().size ()
@@ -607,17 +617,7 @@ public void notifyLocalViewChanges(List<LocalViewChanges> viewChanges) {
607
617
targetData .withLastLimboFreeSnapshotVersion (lastLimboFreeSnapshotVersion );
608
618
queryDataByTarget .put (targetId , updatedTargetData );
609
619
610
- long newSeconds =
611
- updatedTargetData .getLastLimboFreeSnapshotVersion ().getTimestamp ().getSeconds ();
612
-
613
- long oldSeconds =
614
- targetData .getLastLimboFreeSnapshotVersion ().getTimestamp ().getSeconds ();
615
-
616
- long timeDelta = newSeconds - oldSeconds ;
617
-
618
- // Update the target cache if sufficient time has passed since the last
619
- // LastLimboFreeSnapshotVersion
620
- if (timeDelta >= RESUME_TOKEN_MAX_AGE_SECONDS ) {
620
+ if (shouldPersistTargetData (targetData , updatedTargetData , /*change*/ null )) {
621
621
targetCache .updateTargetData (updatedTargetData );
622
622
}
623
623
}
0 commit comments