@@ -176,20 +176,18 @@ export class StatisticsMonitor {
176176
177177 execute ( ) : void {
178178 const counters = this . stats . counters ;
179- const currentMain = counters . get ( this . eventType ) ;
180- counters . set (
181- this . eventType ,
182- Math . max ( this . value , currentMain || 0 ) ,
183- ) ;
184- this . memo = { mainValue : currentMain } ;
179+ const updateCounter = ( eventKey : string ) => {
180+ const currentValue = counters . get ( eventKey ) ;
181+ counters . set ( eventKey , Math . max ( this . value , currentValue || 0 ) ) ;
182+ return currentValue ;
183+ } ;
185184
185+ this . memo = { } ;
186+ this . memo . mainValue = updateCounter ( this . eventType ) ;
186187 if ( this . subtype ) {
187- const currentSubtype = counters . get ( this . eventType ) ;
188- counters . set (
188+ this . memo . subtypeValue = updateCounter (
189189 `${ this . eventType } .${ this . subtype } ` ,
190- Math . max ( this . value , currentSubtype || 0 ) ,
191190 ) ;
192- this . memo = { subtypeValue : currentSubtype } ;
193191 }
194192
195193 this . stats . writeToStorage ( ) ;
@@ -199,21 +197,20 @@ export class StatisticsMonitor {
199197 if ( ! this . memo ) return ;
200198
201199 const counters = this . stats . counters ;
202- if ( this . memo . mainValue === undefined ) {
203- counters . delete ( this . eventType ) ;
204- } else {
205- counters . set ( this . eventType , this . memo . mainValue ) ;
206- }
207-
208- if ( this . subtype ) {
209- if ( this . memo . subtypeValue === undefined ) {
210- counters . delete ( `${ this . eventType } .${ this . subtype } ` ) ;
200+ const restoreCounter = ( eventKey : string , oldValue ?: number ) => {
201+ if ( oldValue === undefined ) {
202+ counters . delete ( eventKey ) ;
211203 } else {
212- counters . set (
213- `${ this . eventType } .${ this . subtype } ` ,
214- this . memo . subtypeValue ,
215- ) ;
204+ counters . set ( eventKey , oldValue ) ;
216205 }
206+ } ;
207+
208+ restoreCounter ( this . eventType , this . memo . mainValue ) ;
209+ if ( this . subtype ) {
210+ restoreCounter (
211+ `${ this . eventType } .${ this . subtype } ` ,
212+ this . memo . subtypeValue ,
213+ ) ;
217214 }
218215
219216 this . stats . writeToStorage ( ) ;
0 commit comments