Skip to content

Commit 56c48a1

Browse files
authored
Refactor localstore.ShouldPersistTargetData (#10911)
1 parent 4b29816 commit 56c48a1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Firestore/core/src/local/local_store.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ bool LocalStore::ShouldPersistTargetData(const TargetData& new_target_data,
417417
int64_t time_delta = new_seconds - old_seconds;
418418
if (time_delta >= kResumeTokenMaxAgeSeconds) return true;
419419

420+
// Update the target cache if sufficient time has passed since the last
421+
// LastLimboFreeSnapshotVersion
422+
int64_t new_limbo_free_seconds =
423+
new_target_data.last_limbo_free_snapshot_version().timestamp().seconds();
424+
int64_t old_limbo_free_seconds =
425+
old_target_data.last_limbo_free_snapshot_version().timestamp().seconds();
426+
int64_t limbo_free_time_delta =
427+
new_limbo_free_seconds - old_limbo_free_seconds;
428+
if (limbo_free_time_delta >= kResumeTokenMaxAgeSeconds) return true;
429+
420430
// Otherwise if the only thing that has changed about a target is its resume
421431
// token then it's not worth persisting. Note that the RemoteStore keeps an
422432
// in-memory view of the currently active targets which includes the current
@@ -465,6 +475,10 @@ void LocalStore::NotifyLocalViewChanges(
465475
target_data.WithLastLimboFreeSnapshotVersion(
466476
last_limbo_free_snapshot_version);
467477
target_data_by_target_[target_id] = updated_target_data;
478+
479+
if (ShouldPersistTargetData(updated_target_data, target_data, {})) {
480+
target_cache_->UpdateTarget(updated_target_data);
481+
}
468482
}
469483
}
470484
});

0 commit comments

Comments
 (0)