@@ -1328,15 +1328,15 @@ export abstract class AbstractProject {
13281328 return [ ] ;
13291329 }
13301330
1331- getEnvFile ( ) : File {
1331+ getEnvFile ( notInitFile ?: boolean ) : File {
13321332
13331333 const prjConfig = this . GetConfiguration ( ) ;
13341334 const targetName = prjConfig . config . mode . toLowerCase ( ) ;
13351335
13361336 const envFilePath = `${ this . getEideDir ( ) . path } ${ File . sep } ${ targetName } .env.ini` ;
13371337 const envFile = new File ( envFilePath ) ;
13381338
1339- if ( ! envFile . IsFile ( ) ) {
1339+ if ( ! notInitFile && ! envFile . IsFile ( ) ) {
13401340 const defTxt : string [ ] = [
13411341 `###########################################################` ,
13421342 `# project environment variables` ,
@@ -1361,37 +1361,42 @@ export abstract class AbstractProject {
13611361 return envFile ;
13621362 }
13631363
1364+ private env_lastGetTime : number = 0 ;
1365+ private env_lastReadTime : number = 0 ;
1366+ private env_lastRawEnvObj : { [ name : string ] : any } | undefined ;
13641367 getProjectEnv ( ) : { [ name : string ] : any } | undefined {
1368+ try {
13651369
1366- const envs = this . getRawEnv ( ) ;
1367- if ( envs == undefined ) { return ; }
1368-
1369- // remove none-string obj
1370- for ( const key in envs ) {
1371- if ( typeof envs [ key ] == 'object' ||
1372- Array . isArray ( envs [ key ] ) ||
1373- key . includes ( ' ' ) ) {
1374- delete envs [ key ] ;
1370+ // limit read interval (150 ms), increase speed
1371+ if ( this . env_lastRawEnvObj != undefined &&
1372+ Date . now ( ) - this . env_lastGetTime < 150 ) {
1373+ return this . env_lastRawEnvObj ;
13751374 }
1376- }
1377-
1378- // return env objects
1379- return envs ;
1380- }
13811375
1382- private lastReadTime : number = 0 ;
1383- private lastRawEnvObj : { [ name : string ] : any } | undefined ;
1384- private getRawEnv ( ) : { [ name : string ] : any } | undefined {
1385- try {
1386- const envFile = this . getEnvFile ( ) ;
1376+ // is env need update ?
1377+ const envFile = this . getEnvFile ( true ) ;
13871378 if ( envFile . IsFile ( ) ) {
13881379 const lastMdTime = fs . statSync ( envFile . path ) . mtimeMs ;
1389- if ( this . lastRawEnvObj == undefined ||
1390- lastMdTime > this . lastReadTime ) { // update env
1391- this . lastRawEnvObj = ini . parse ( envFile . Read ( ) ) ;
1392- this . lastReadTime = fs . statSync ( envFile . path ) . mtimeMs ;
1380+ if ( this . env_lastRawEnvObj == undefined ||
1381+ lastMdTime > this . env_lastReadTime ) {
1382+
1383+ // update env
1384+ this . env_lastRawEnvObj = ini . parse ( envFile . Read ( ) ) ;
1385+ this . env_lastReadTime = lastMdTime ;
1386+
1387+ // delete non-string obj
1388+ for ( const key in this . env_lastRawEnvObj ) {
1389+ if ( typeof this . env_lastRawEnvObj [ key ] == 'object' ||
1390+ Array . isArray ( this . env_lastRawEnvObj [ key ] ) ||
1391+ key . includes ( ' ' ) ) {
1392+ delete this . env_lastRawEnvObj [ key ] ;
1393+ }
1394+ }
13931395 }
1394- return this . lastRawEnvObj ;
1396+
1397+ // return env objects
1398+ this . env_lastGetTime = Date . now ( ) ;
1399+ return this . env_lastRawEnvObj ;
13951400 }
13961401 } catch ( error ) {
13971402 GlobalEvent . emit ( 'msg' , ExceptionToMessage ( error , 'Hidden' ) ) ;
0 commit comments