compact method
Forgets the change records up to upTo, a version the persisted
copy holds (the CacheDelta.version just stored): the removals and
per-entity stamps at or before it are dropped, so they are not
scanned again by changesSince. A cache that was never compacted
forgets its removals once they pass a thousand (and the entity count,
e.g. after a large gc) and answers older versions with a
CacheDelta.full delta (a store rewrites every entity); once
compacted, only a far larger pile (a store that stopped saving) is.
Afterwards changesSince a version older than upTo answers with a
full delta: call it with the oldest version any copy still needs (with
one store, the one it just saved).
Implementation
@override
void compact({required int upTo}) {
_compacted = true;
final v = upTo < _version ? upTo : _version;
if (v <= 0) return;
_changedAt.removeWhere((_, at) => at <= v);
_removedAt.removeWhere((_, at) => at <= v);
for (final stamps in _fieldChangedAt.values) {
stamps.removeWhere((_, at) => at <= v);
}
_fieldChangedAt.removeWhere((_, stamps) => stamps.isEmpty);
// Versions before [v] now get a full delta, which covers these.
_fieldsSince.removeWhere((_, since) => since <= v);
if (v > _fullSince) _fullSince = v;
}