Skip to content

Commit 9f5a6c4

Browse files
author
Marcin Mazurek
committed
[DDW-1088] Keep track of reported progress in memory and only send new messages on actual change
1 parent f37a79a commit 9f5a6c4

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

source/main/utils/handleCheckBlockReplayProgress.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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';
76
import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress';
87
import type { GetBlockSyncProgressType } from '../../common/ipc/api';
98
import { BlockSyncType } from '../../common/types/cardano-node.types';
@@ -45,27 +44,42 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4544

4645
const applicationStartDate = moment.utc();
4746

48-
const createHandleNewLine = (mainWindow: BrowserWindow) =>
49-
debounce((line: string) => {
47+
const createHandleNewLogLine = (mainWindow: BrowserWindow) => {
48+
const lastReportedProgressByType: Record<BlockSyncType, number> = {
49+
[BlockSyncType.pushingLedger]: 0,
50+
[BlockSyncType.replayedBlock]: 0,
51+
[BlockSyncType.validatingChunk]: 0,
52+
};
53+
54+
return (line: string) => {
5055
if (
5156
!isItFreshLog(applicationStartDate, line) ||
5257
!containProgressKeywords(line)
5358
) {
5459
return;
5560
}
5661

57-
const percentage = line.match(/Progress:([\s\d.,]+)%/)?.[1];
58-
const progressType = getProgressType(line);
59-
if (!percentage || !progressType) {
62+
const unparsedProgress = line.match(/Progress:([\s\d.,]+)%/)?.[1];
63+
const type = getProgressType(line);
64+
if (!unparsedProgress || !type) {
6065
return;
6166
}
62-
const finalProgressPercentage = parseFloat(percentage);
6367

64-
getBlockSyncProgressChannel.send(
65-
{ progress: finalProgressPercentage, type: progressType },
66-
mainWindow.webContents
67-
);
68-
}, 1000);
68+
const progress = Math.floor(parseFloat(unparsedProgress));
69+
70+
if (lastReportedProgressByType[type] !== progress) {
71+
console.log(
72+
`Reporting more progress. Old: ${lastReportedProgressByType[type]}, new ${progress}`
73+
);
74+
lastReportedProgressByType[type] = progress;
75+
76+
getBlockSyncProgressChannel.send(
77+
{ progress, type },
78+
mainWindow.webContents
79+
);
80+
}
81+
};
82+
};
6983

7084
export const handleCheckBlockReplayProgress = (
7185
mainWindow: BrowserWindow,
@@ -84,6 +98,6 @@ export const handleCheckBlockReplayProgress = (
8498
useWatchFile: environment.isWindows,
8599
});
86100

87-
const handleNewLine = createHandleNewLine(mainWindow);
88-
tail.on('line', handleNewLine);
101+
const handleNewLogLine = createHandleNewLogLine(mainWindow);
102+
tail.on('line', handleNewLogLine);
89103
};

source/renderer/app/components/loading/syncing-connecting/SyncingProgress/SyncingProgress.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const SyncingProgress: FC<Props> = (props, { intl }: Context) => (
7979
key={type}
8080
className={makePercentageCellStyles(props[type] === 100)}
8181
>
82-
{Math.floor(props[type])}%
82+
{props[type]}%
8383
</div>
8484
))}
8585
</div>

0 commit comments

Comments
 (0)