From d8f05daee5681be8194bc3f4f2c446b27733ea49 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Mon, 23 Dec 2024 12:10:13 +0000 Subject: [PATCH] Logs: limit history count to the retention limit Change-type: patch --- src/features/device-logs/lib/read.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/features/device-logs/lib/read.ts b/src/features/device-logs/lib/read.ts index fd2cd9084..7c7ddbdd3 100644 --- a/src/features/device-logs/lib/read.ts +++ b/src/features/device-logs/lib/read.ts @@ -21,6 +21,7 @@ import { getNanoTimestamp } from '../../../lib/utils.js'; import type { SetupOptions } from '../../../index.js'; import { LOGS_DEFAULT_HISTORY_COUNT, + LOGS_DEFAULT_RETENTION_LIMIT, LOGS_DEFAULT_SUBSCRIPTION_COUNT, LOGS_HEARTBEAT_INTERVAL, LOGS_READ_STREAM_FLUSH_INTERVAL, @@ -202,21 +203,20 @@ function getCount( countParam: string | undefined, defaultCount: number, ): number { + let count: number; if (countParam == null) { - return defaultCount; - } - - if (countParam === 'all') { - return Infinity; - } - - const parsedCount = parseInt(countParam, 10); - - if (!Number.isNaN(parsedCount)) { - return parsedCount; + count = defaultCount; + } else if (countParam === 'all') { + count = Infinity; } else { - return defaultCount; + const parsedCount = parseInt(countParam, 10); + if (!Number.isNaN(parsedCount)) { + count = parsedCount; + } else { + count = defaultCount; + } } + return Math.min(count, LOGS_DEFAULT_RETENTION_LIMIT); } function getHistory(