1
1
import { DocumentSnapshot , SvelteSnapshotOptions } from './DocumentSnapshot' ;
2
+ import { Logger } from '../../logger' ;
2
3
3
4
export class SnapshotManager {
4
- constructor (
5
- private projectFiles : string [ ]
6
- ) { }
7
-
8
5
private documents : Map < string , DocumentSnapshot > = new Map ( ) ;
6
+ private lastLogged = new Date ( new Date ( ) . getTime ( ) - 60_001 ) ;
7
+
8
+ constructor ( private projectFiles : string [ ] ) { }
9
9
10
10
updateByFileName ( fileName : string , options : SvelteSnapshotOptions ) {
11
11
if ( ! this . has ( fileName ) ) {
@@ -36,6 +36,8 @@ export class SnapshotManager {
36
36
prev . destroyFragment ( ) ;
37
37
}
38
38
39
+ this . logStatistics ( ) ;
40
+
39
41
return this . documents . set ( fileName , snapshot ) ;
40
42
}
41
43
@@ -44,8 +46,7 @@ export class SnapshotManager {
44
46
}
45
47
46
48
delete ( fileName : string ) {
47
- this . projectFiles = this . projectFiles
48
- . filter ( s => s !== fileName ) ;
49
+ this . projectFiles = this . projectFiles . filter ( ( s ) => s !== fileName ) ;
49
50
return this . documents . delete ( fileName ) ;
50
51
}
51
52
@@ -56,4 +57,26 @@ export class SnapshotManager {
56
57
getProjectFileNames ( ) {
57
58
return [ ...this . projectFiles ] ;
58
59
}
60
+
61
+ private logStatistics ( ) {
62
+ const date = new Date ( ) ;
63
+ // Don't use setInterval because that will keep tests running forever
64
+ if ( date . getTime ( ) - this . lastLogged . getTime ( ) > 60_000 ) {
65
+ this . lastLogged = date ;
66
+
67
+ const projectFiles = this . getProjectFileNames ( ) ;
68
+ const allFiles = Array . from ( new Set ( [ ...projectFiles , ...this . getFileNames ( ) ] ) ) ;
69
+ Logger . log (
70
+ `SnapshotManager File Statistics:\n` +
71
+ `Project files: ${ projectFiles . length } \n` +
72
+ `Svelte files: ${
73
+ allFiles . filter ( ( name ) => name . endsWith ( '.svelte' ) ) . length
74
+ } \n` +
75
+ `From node_modules: ${
76
+ allFiles . filter ( ( name ) => name . includes ( 'node_modules' ) ) . length
77
+ } \n` +
78
+ `Total: ${ allFiles . length } ` ,
79
+ ) ;
80
+ }
81
+ }
59
82
}
0 commit comments