Skip to content

Commit

Permalink
limit max query results to 1000; add jsdoc for ResultsGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry8192 committed Nov 4, 2024
1 parent b931505 commit 3ddd96a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ interface ResultsGroupProps {
}

/**
* Renders a group of results. Each group contains a list of results from a single page.
*
* @param props
* @param props.isAllExpanded
* @param props.queryResults
* @return
*/
const ResultsGroup = ({
isAllExpanded,
Expand Down
13 changes: 11 additions & 2 deletions src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint max-lines: ["error", 400] */
/* eslint max-lines: ["error", 450] */
import {
Decoder,
DecoderOptionsType,
Expand Down Expand Up @@ -33,6 +33,8 @@ import {
} from "./utils";


const MAX_RESULT_COUNT = 1_000;

/**
* Class to manage the retrieval and decoding of a given log file.
*/
Expand All @@ -51,6 +53,8 @@ class LogFileManager {

#decoder: Decoder;

#queryCount: number = 0;

/**
* Private constructor for LogFileManager. This is not intended to be invoked publicly.
* Instead, use LogFileManager.create() to create a new instance of the class.
Expand Down Expand Up @@ -287,6 +291,7 @@ class LogFileManager {
*/
startQuery (queryString: string, isRegex: boolean, isCaseSensitive: boolean): void {
this.#queryId++;
this.#queryCount = 0;

// If the query string is empty, or there are no logs, return
if ("" === queryString || 0 === this.#numEvents) {
Expand Down Expand Up @@ -318,7 +323,7 @@ class LogFileManager {
chunkBeginIdx: number,
queryRegex: RegExp
): void {
if (queryId !== this.#queryId) {
if (queryId !== this.#queryId || MAX_RESULT_COUNT < this.#queryCount) {
// Current task no longer corresponds to the latest query in the LogFileManager.
return;
}
Expand All @@ -333,6 +338,10 @@ class LogFileManager {
decodedEvents?.forEach(([message, , , logEventNum]) => {
const matchResult = message.match(queryRegex);
if (null !== matchResult && "number" === typeof matchResult.index) {
this.#queryCount++;
if (MAX_RESULT_COUNT < this.#queryCount) {
return;
}
const pageNum = Math.ceil(logEventNum / this.#pageSize);
if (false === results.has(pageNum)) {
results.set(pageNum, []);
Expand Down

0 comments on commit 3ddd96a

Please sign in to comment.