Skip to content

Commit

Permalink
add better guards for search, and fix range
Browse files Browse the repository at this point in the history
  • Loading branch information
davemarco committed Jan 10, 2025
1 parent edca031 commit 4b9cfca
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,6 @@ class LogFileManager {
}
}

/**
* Queries a chunk of log events, sends the results, and schedules the next chunk query if more
* log events remain.
*
* @param queryId
* @param chunkBeginIdx
* @param queryRegex
*/
#queryChunkAndScheduleNext (
queryId: number,
chunkBeginIdx: number,
Expand All @@ -383,7 +375,17 @@ class LogFileManager {
// Current task no longer corresponds to the latest query in the LogFileManager.
return;
}
const chunkEndIdx = Math.min(chunkBeginIdx + QUERY_CHUNK_SIZE, this.#numEvents);

const filteredLogEventMap = this.#decoder.getFilteredLogEventMap();
const numActiveEvents: number = filteredLogEventMap ?
filteredLogEventMap.length :
this.#numEvents;

if (0 === numActiveEvents) {
return;
}

const chunkEndIdx = Math.min(chunkBeginIdx + QUERY_CHUNK_SIZE, numActiveEvents);
const results: QueryResults = new Map();
const decodedEvents = this.#decoder.decodeRange(
chunkBeginIdx,
Expand All @@ -400,13 +402,13 @@ class LogFileManager {
// The query progress takes the maximum of the progress based on the number of events
// queried over total log events, and the number of results over the maximum result limit.
const progress = Math.max(
chunkEndIdx / this.#numEvents,
chunkEndIdx / numActiveEvents,
this.#queryCount / MAX_QUERY_RESULT_COUNT
);

this.#onQueryResults(progress, results);

if (chunkEndIdx < this.#numEvents && MAX_QUERY_RESULT_COUNT > this.#queryCount) {
if (chunkEndIdx < numActiveEvents && MAX_QUERY_RESULT_COUNT > this.#queryCount) {
defer(() => {
this.#queryChunkAndScheduleNext(queryId, chunkEndIdx, queryRegex);
});
Expand Down

0 comments on commit 4b9cfca

Please sign in to comment.