From eb706d3a44a051e7d7ee90c64c94a0f9e7b29f7d Mon Sep 17 00:00:00 2001 From: Dave Marco Date: Wed, 9 Oct 2024 15:34:11 +0000 Subject: [PATCH] kirk review --- .../src/services/LogFileManager/index.ts | 6 +-- .../src/services/LogFileManager/utils.ts | 38 ++++++++++--------- new-log-viewer/src/typings/worker.ts | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/new-log-viewer/src/services/LogFileManager/index.ts b/new-log-viewer/src/services/LogFileManager/index.ts index 1641c5ab..271ba2bd 100644 --- a/new-log-viewer/src/services/LogFileManager/index.ts +++ b/new-log-viewer/src/services/LogFileManager/index.ts @@ -199,7 +199,7 @@ class LogFileManager { const { pageBegin, pageEnd, - matching, + matchingEvent, } = this.#getCursorData(cursor, numActiveEvents); const results = this.#decoder.decodeRange( pageBegin, @@ -231,8 +231,8 @@ class LogFileManager { const newPageNum: number = getChunkNum(pageBegin + 1, this.#pageSize); const matchingLogEventNum = 1 + ( null !== filteredLogEventMap ? - (filteredLogEventMap[matching] as number) : - matching + (filteredLogEventMap[matchingEvent] as number) : + matchingEvent ); return { diff --git a/new-log-viewer/src/services/LogFileManager/utils.ts b/new-log-viewer/src/services/LogFileManager/utils.ts index 743c9496..3c7605b2 100644 --- a/new-log-viewer/src/services/LogFileManager/utils.ts +++ b/new-log-viewer/src/services/LogFileManager/utils.ts @@ -37,31 +37,29 @@ const getPageNumCursorData = ( const pageBegin: ActiveLogCollectionEventIdx = (pageNum - 1) * pageSize; const pageEnd: ActiveLogCollectionEventIdx = Math.min(numActiveEvents, pageBegin + pageSize); - const matching: ActiveLogCollectionEventIdx = + const matchingEvent: ActiveLogCollectionEventIdx = eventPositionOnPage === EVENT_POSITION_ON_PAGE.TOP ? pageBegin : pageEnd - 1; - return {pageBegin, pageEnd, matching}; + return {pageBegin, pageEnd, matchingEvent}; }; /** - * Gets the index, `i`, into the active log event collection. Behaviour varies - * depending on whether the active collection is filtered or unfiltered. - * - * If the active collection if unfiltered, returned clamped `logEventIdx` : - * - `i` is `logEventIdx` clamped within [0, collection.length). - * - * If the active collection is filtered, find the "nearest" event: - * - `i` is the largest index where `filteredLogEventMap[i]` <= `logEventIdx`, or - * - `i` is `0` if `logEventIdx < filteredLogEventMap[0]`. + * Gets the `ActiveLogCollectionEventIdx` that's nearest to `logEventIdx`. Specifically: + * - If no filter is set, the nearest `ActiveLogCollectionEventIdx` is: + * - `logEventIdx` if it's in the range of the unfiltered log events collection. + * - the bound of the collection nearest to `logEventIdx` if it's not in the collection's range. + * - If a filter is set, the nearest `ActiveLogCollectionEventIdx` is: + * - the largest index, `i`, where `filteredLogEventMap[i] <= logEventIdx`; or + * - `0` if `logEventIdx < filteredLogEventMap[0]`. * * @param logEventIdx * @param numActiveEvents * @param filteredLogEventMap * @return */ -const getActiveLogCollectionEventIdx = ( +const getNearestActiveLogCollectionEventIdx = ( logEventIdx: number, numActiveEvents: number, filteredLogEventMap: FilteredLogEventMap, @@ -92,14 +90,18 @@ const getEventNumCursorData = ( pageSize: number, filteredLogEventMap: FilteredLogEventMap ): CursorData => { - const matching: ActiveLogCollectionEventIdx = - getActiveLogCollectionEventIdx(logEventNum - 1, numActiveEvents, filteredLogEventMap); + const matchingEvent: ActiveLogCollectionEventIdx = + getNearestActiveLogCollectionEventIdx( + logEventNum - 1, + numActiveEvents, + filteredLogEventMap + ); const pageBegin: ActiveLogCollectionEventIdx = - (getChunkNum(matching + 1, pageSize) - 1) * pageSize; + (getChunkNum(matchingEvent + 1, pageSize) - 1) * pageSize; const pageEnd: ActiveLogCollectionEventIdx = Math.min(numActiveEvents, pageBegin + pageSize); - return {pageBegin, pageEnd, matching}; + return {pageBegin, pageEnd, matchingEvent}; }; /** @@ -116,8 +118,8 @@ const getLastEventCursorData = ( const pageBegin: ActiveLogCollectionEventIdx = (getChunkNum(numActiveEvents, pageSize) - 1) * pageSize; const pageEnd: ActiveLogCollectionEventIdx = Math.min(numActiveEvents, pageBegin + pageSize); - const matching: ActiveLogCollectionEventIdx = pageEnd - 1; - return {pageBegin, pageEnd, matching}; + const matchingEvent: ActiveLogCollectionEventIdx = pageEnd - 1; + return {pageBegin, pageEnd, matchingEvent}; }; /** diff --git a/new-log-viewer/src/typings/worker.ts b/new-log-viewer/src/typings/worker.ts index e26fe839..24b2afb9 100644 --- a/new-log-viewer/src/typings/worker.ts +++ b/new-log-viewer/src/typings/worker.ts @@ -56,7 +56,7 @@ type CursorType = { type CursorData = { pageBegin: ActiveLogCollectionEventIdx; pageEnd: ActiveLogCollectionEventIdx; - matching: ActiveLogCollectionEventIdx; + matchingEvent: ActiveLogCollectionEventIdx; }; /**