@@ -3,7 +3,6 @@ import fs from 'fs';
33import moment from 'moment' ;
44import path from 'path' ;
55import { Tail } from 'tail' ;
6- import debounce from 'lodash/debounce' ;
76import { getBlockSyncProgressChannel } from '../ipc/get-block-sync-progress' ;
87import type { GetBlockSyncProgressType } from '../../common/ipc/api' ;
98import { BlockSyncType } from '../../common/types/cardano-node.types' ;
@@ -45,27 +44,42 @@ function getProgressType(line: string): GetBlockSyncProgressType | null {
4544
4645const 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 ( / P r o g r e s s : ( [ \s \d . , ] + ) % / ) ?. [ 1 ] ;
58- const progressType = getProgressType ( line ) ;
59- if ( ! percentage || ! progressType ) {
62+ const unparsedProgress = line . match ( / P r o g r e s s : ( [ \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
7084export 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} ;
0 commit comments