From ec485ef88d0eedebf3b0a38c277073fec14a1d99 Mon Sep 17 00:00:00 2001 From: Pavan Kumar VH Date: Thu, 3 Sep 2026 10:28:02 +0530 Subject: [PATCH] Improve readability of count validation in lazy-response-ads The original code used a ternary inside Math.min/Math.max which was hard to read. Extracted the Number.isFinite check into a separate variable for clarity. This is a pure refactor with no behavioral change - the logic is identical. --- common/src/util/lazy-response-ads.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/common/src/util/lazy-response-ads.ts b/common/src/util/lazy-response-ads.ts index 1b491a44d8..750a5b15bd 100644 --- a/common/src/util/lazy-response-ads.ts +++ b/common/src/util/lazy-response-ads.ts @@ -58,9 +58,11 @@ export function requestLazyResponseAds(params: { onAd: (ad: T) => void }): Promise | null { const { queue, messageId, fetchOne, onAd } = params - const count = Number.isFinite(params.count) - ? Math.min(MAX_RESPONSE_AD_POOL_SIZE, Math.max(0, Math.floor(params.count))) - : 0 + const safeCount = Number.isFinite(params.count) ? params.count : 0 + const count = Math.min( + MAX_RESPONSE_AD_POOL_SIZE, + Math.max(0, Math.floor(safeCount)), + ) const previousTarget = queue.targetCounts.get(messageId) ?? 0 if (count <= previousTarget) return queue.inFlight.get(messageId) ?? null