Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Junhao Liao <junhao@junhao.ca>
  • Loading branch information
Henry8192 and junhaoliao authored Oct 19, 2024
1 parent b732607 commit 45e5e61
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions new-log-viewer/src/services/LogFileManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class LogFileManager {
* @param params.fileName
* @param params.onDiskFileSizeInBytes
* @param params.pageSize Page size for setting up pagination.
* @param params.onQueryResults The callback function to handle query results.
*/
constructor ({decoder, fileName, onDiskFileSizeInBytes, pageSize, onQueryResults}: {
decoder: Decoder,
Expand Down Expand Up @@ -278,13 +277,16 @@ class LogFileManager {
}

/**
* Searches for log events based on the given search string.
* Creates a RegExp object based on the given search string and options,
* and starts querying the first log chunk.
*
* @param searchString
* @param isRegex
* @param isCaseSensitive
*/
startQuery (searchString: string, isRegex: boolean, isCaseSensitive: boolean): void {
this.#queryId++;

// If the search string is empty, or there are no logs, return
if ("" === searchString || 0 === this.#numEvents) {
return;
Expand All @@ -299,15 +301,16 @@ class LogFileManager {
"i";
const searchRegex = new RegExp(regexPattern, regexFlags);

this.#searchChunkAndScheduleNext(this.#queryId++, 0, searchRegex);
this.#searchChunkAndScheduleNext(this.#queryId, 0, searchRegex);
}

/**
* Searches for log events in the given range, then schedules itself to search the next chunk.
* Queries a chunk of log events, sends the results,
* and schedules the next chunk query if more log events remain.
*
* @param queryId
* @param beginSearchIdx The beginning index of the search range.
* @param searchRegex The regular expression to search.
* @param searchRegex
*/
#searchChunkAndScheduleNext (
queryId: number,
Expand Down
2 changes: 1 addition & 1 deletion new-log-viewer/src/services/MainWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const postResp = <T extends WORKER_RESP_CODE>(


/**
* Post a response of a query chunk.
* Post a response for a chunk of query results.
*
* @param queryResults
*/
Expand Down
2 changes: 1 addition & 1 deletion new-log-viewer/src/utils/time.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Defers the execution of a callback function until the call stack is clear.
*
* @param callbackFn The callback function to be deferred.
* @param callbackFn The callback function to be executed.
*/
const defer = (callbackFn: () => void) => {
setTimeout(callbackFn, 0);
Expand Down

0 comments on commit 45e5e61

Please sign in to comment.