File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,15 @@ class OperationIdCleanerCommand extends Command {
2424 * @param command
2525 */
2626 async execute ( ) {
27+ const memoryBytes = this . operationIdService . getOperationIdMemoryCacheSizeBytes ( ) ;
28+ const fileBytes = await this . operationIdService . getOperationIdFileCacheSizeBytes ( ) ;
29+ const bytesInMegabyte = 1024 * 1024 ;
30+ this . logger . debug (
31+ `Operation cache footprint before cleanup: memory=${ (
32+ memoryBytes / bytesInMegabyte
33+ ) . toFixed ( 2 ) } MB, files=${ ( fileBytes / bytesInMegabyte ) . toFixed ( 2 ) } MB`,
34+ ) ;
35+
2736 this . logger . debug ( 'Starting command for removal of expired cache files' ) ;
2837 const timeToBeDeleted = Date . now ( ) - OPERATION_ID_COMMAND_CLEANUP_TIME_MILLS ;
2938 await this . repositoryModuleManager . removeOperationIdRecord ( timeToBeDeleted , [
Original file line number Diff line number Diff line change @@ -150,6 +150,30 @@ class OperationIdService {
150150 delete this . memoryCachedHandlersData [ operationId ] ;
151151 }
152152
153+ getOperationIdMemoryCacheSizeBytes ( ) {
154+ let total = 0 ;
155+ for ( const operationId in this . memoryCachedHandlersData ) {
156+ const { data } = this . memoryCachedHandlersData [ operationId ] ;
157+ total += Buffer . from ( JSON . stringify ( data ) ) . byteLength ;
158+ }
159+ return total ;
160+ }
161+
162+ async getOperationIdFileCacheSizeBytes ( ) {
163+ const cacheFolderPath = this . fileService . getOperationIdCachePath ( ) ;
164+ const cacheFolderExists = await this . fileService . pathExists ( cacheFolderPath ) ;
165+ if ( ! cacheFolderExists ) return 0 ;
166+
167+ const fileList = await this . fileService . readDirectory ( cacheFolderPath ) ;
168+ let total = 0 ;
169+ for ( const fileName of fileList ) {
170+ // eslint-disable-next-line no-await-in-loop
171+ const stats = await this . fileService . stat ( path . join ( cacheFolderPath , fileName ) ) ;
172+ total += stats . size ;
173+ }
174+ return total ;
175+ }
176+
153177 async removeExpiredOperationIdMemoryCache ( expiredTimeout ) {
154178 const now = Date . now ( ) ;
155179 let deleted = 0 ;
You can’t perform that action at this time.
0 commit comments