fix coalesce interval

Summary: The delay should be using the `_coalescenceInterval` before it gets updated by `intervalIncrement`

Differential Revision: D60834604

fbshipit-source-id: 1bf18725a302843c12b50711f0628493c4a04e61
This commit is contained in:
Maxime Ollivier 2024-08-06 11:37:51 -07:00 committed by Facebook GitHub Bot
parent c1c8f5acae
commit 0e2db06bdd

View file

@ -57,21 +57,22 @@ static BOOL _isViewVisible(UIView *_Nullable view, IGListAdaptiveCoalescingExper
const IGListAdaptiveCoalescingExperimentConfig config = _adaptiveCoalescingExperimentConfig;
const NSTimeInterval timeSinceLastUpdate = -[_lastUpdateStartDate timeIntervalSinceNow];
const BOOL isViewVisible = _isViewVisible(view, config);
const NSTimeInterval currentCoalescenceInterval = _coalescenceInterval;
if (isViewVisible) {
if (!_lastUpdateStartDate || timeSinceLastUpdate > _coalescenceInterval) {
if (!_lastUpdateStartDate || timeSinceLastUpdate > currentCoalescenceInterval) {
// It's been long enough, so lets reset interval and perform update right away
_coalescenceInterval = config.minInterval;
[self _performUpdate];
return;
} else {
// If we keep hitting the delay, lets increase it.
_coalescenceInterval = MIN(_coalescenceInterval + config.intervalIncrement, config.maxInterval);
_coalescenceInterval = MIN(currentCoalescenceInterval + config.intervalIncrement, config.maxInterval);
}
}
// Delay by the time remaining in the interval
const NSTimeInterval remainingTime = isViewVisible ? (_coalescenceInterval - timeSinceLastUpdate) : config.maxInterval;
const NSTimeInterval remainingTime = isViewVisible ? (currentCoalescenceInterval - timeSinceLastUpdate) : config.maxInterval;
const NSTimeInterval remainingTimeCapped = MAX(remainingTime, 0);
_hasQueuedUpdate = YES;