stalePruneCutoff function
The staleBefore cutoff for merging incomingCount nodes into a cached
set of existingCount nodes at time now: now minus kStaleNodeMaxAge.
A node is pruned only if its kMissingSinceKey stamp — itself written by
an earlier eligible changing merge — is at or before this.
Returns null — the capture neither stamps nor prunes — when:
hasOpenOverlay: a dialog / sheet / menu is open, so the page layer under it is (partly) hidden from semantics and absence proves nothing;- the capture is tiny relative to what is cached (< kMinPruneCoverage);
nowis not parseable.
Implementation
DateTime? stalePruneCutoff({
required String? now,
required int existingCount,
required int incomingCount,
bool hasOpenOverlay = false,
}) {
if (hasOpenOverlay) return null;
if (existingCount == 0) return null;
if (incomingCount < existingCount * kMinPruneCoverage) return null;
final ref = now == null ? null : DateTime.tryParse(now);
return ref?.subtract(kStaleNodeMaxAge);
}