Skip to content

Commit 9b48a33

Browse files
author
Lucas Araujo
committed
[DDW-1088] Use debounce
1 parent 761d05a commit 9b48a33

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

source/main/utils/handleCheckBlockReplayProgress.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import fs from 'fs';
33
import moment from 'moment';
44
import path from 'path';
55
import { Tail } from 'tail';
6+
import debounce from 'lodash/debounce';
67
import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress';
7-
import type { GetBlockSyncProgressType } from '../../common/ipc/api';
8+
import type {
9+
GetBlockSyncProgressMainResponse,
10+
GetBlockSyncProgressRendererRequest,
11+
GetBlockSyncProgressType,
12+
} from '../../common/ipc/api';
813
import { BlockSyncType } from '../../common/types/cardano-node.types';
914
import { isItFreshLog } from './blockSyncProgressHelpers';
1015
import { environment } from '../environment';
16+
import { MainIpcChannel } from '../ipc/lib/MainIpcChannel';
1117

1218
const blockKeyword = 'Replayed block';
1319
const validatingChunkKeyword = 'Validating chunk';
@@ -44,6 +50,13 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4450

4551
const applicationStartDate = moment.utc();
4652

53+
const debouncedSyncProgress = debounce<
54+
MainIpcChannel<
55+
GetBlockSyncProgressRendererRequest,
56+
GetBlockSyncProgressMainResponse
57+
>['send']
58+
>((...args) => getBlockSyncProgressChannel.send(...args), 1000);
59+
4760
export const handleCheckBlockReplayProgress = (
4861
mainWindow: BrowserWindow,
4962
logsDirectoryPath: string
@@ -57,7 +70,7 @@ export const handleCheckBlockReplayProgress = (
5770
// using fs.watchFile instead of fs.watch on Windows because of Node API inconsistency:
5871
// https://nodejs.org/dist/latest-v14.x/docs/api/fs.html#fs_caveats
5972
// https://github.com/lucagrulla/node-tail/issues/137
60-
useWatchFile: environment.isWindows,
73+
useWatchFile: true,
6174
});
6275

6376
tail.on('line', (line) => {
@@ -75,7 +88,7 @@ export const handleCheckBlockReplayProgress = (
7588
}
7689
const finalProgressPercentage = parseFloat(percentage);
7790
// Send result to renderer process (NetworkStatusStore)
78-
getBlockSyncProgressChannel.send(
91+
debouncedSyncProgress(
7992
{ progress: finalProgressPercentage, type: progressType },
8093
mainWindow.webContents
8194
);

0 commit comments

Comments
 (0)