@@ -351,6 +351,8 @@ class SystemStore extends EventEmitter {
351
351
this . is_finished_initial_load = false ;
352
352
this . START_REFRESH_THRESHOLD = 10 * 60 * 1000 ;
353
353
this . FORCE_REFRESH_THRESHOLD = 60 * 60 * 1000 ;
354
+ this . LOAD_FRESH_THRESHOLD = config . LOAD_FRESH_THRESHOLD || 100 ;
355
+ this . READ_NEW_DATA_CONCURRENCY = config . READ_NEW_DATA_CONCURRENCY || 5 ;
354
356
this . _load_serial = new semaphore . Semaphore ( 1 , { warning_timeout : this . START_REFRESH_THRESHOLD } ) ;
355
357
for ( const col of COLLECTIONS ) {
356
358
db_client . instance ( ) . define_collection ( col ) ;
@@ -407,30 +409,39 @@ class SystemStore extends EventEmitter {
407
409
}
408
410
409
411
async load ( since ) {
412
+ /*const now_diff = Date.now() - this.last_update_time;
413
+ if (now_diff < this.LOAD_FRESH_THRESHOLD) {
414
+ dbg.log0("fresh enough, skipping load this.last_update_time =", this.last_update_time, ", since =", since, ", now diff =", now_diff);
415
+ return this.data;
416
+ }*/
417
+
418
+ const new_data = new SystemStoreData ( ) ;
419
+
410
420
// serializing load requests since we have to run a fresh load after the previous one will finish
411
421
// because it might not see the latest changes if we don't reload right after make_changes.
412
422
return this . _load_serial . surround ( async ( ) => {
413
423
try {
414
- dbg . log3 ( 'SystemStore: loading ...' ) ;
424
+ dbg . log3 ( 'SystemStore: loading ... this.last_update_time =' , this . last_update_time , ", since =" , since /*, ", now diff = ", now_diff*/ ) ;
415
425
416
426
// If we get a load request with an timestamp older then our last update time
417
427
// we ensure we load everyting from that timestamp by updating our last_update_time.
418
428
if ( ! _ . isUndefined ( since ) && since < this . last_update_time ) {
419
- dbg . log0 ( 'SystemStore.load: Got load request with a timestamp older then my last update time' ) ;
429
+ dbg . log0 ( 'SystemStore.load: Got load request with a timestamp' , since , ' older than my last update time', this . last_update_time ) ;
420
430
this . last_update_time = since ;
421
431
}
422
432
this . master_key_manager . load_root_key ( ) ;
423
- const new_data = new SystemStoreData ( ) ;
424
433
let millistamp = time_utils . millistamp ( ) ;
425
434
await this . _register_for_changes ( ) ;
426
435
await this . _read_new_data_from_db ( new_data ) ;
427
436
const secret = await os_utils . read_server_secret ( ) ;
428
437
this . _server_secret = secret ;
429
- dbg . log1 ( 'SystemStore: fetch took' , time_utils . millitook ( millistamp ) ) ;
430
- dbg . log1 ( 'SystemStore: fetch size' , size_utils . human_size ( JSON . stringify ( new_data ) . length ) ) ;
431
- dbg . log1 ( 'SystemStore: fetch data' , util . inspect ( new_data , {
432
- depth : 4
433
- } ) ) ;
438
+ if ( dbg . should_log ( 1 ) ) { //param should match below logs' level
439
+ dbg . log1 ( 'SystemStore: fetch took' , time_utils . millitook ( millistamp ) ) ;
440
+ dbg . log1 ( 'SystemStore: fetch size' , size_utils . human_size ( JSON . stringify ( new_data ) . length ) ) ;
441
+ dbg . log1 ( 'SystemStore: fetch data' , util . inspect ( new_data , {
442
+ depth : 4
443
+ } ) ) ;
444
+ }
434
445
this . old_db_data = this . _update_data_from_new ( this . old_db_data || { } , new_data ) ;
435
446
this . data = _ . cloneDeep ( this . old_db_data ) ;
436
447
millistamp = time_utils . millistamp ( ) ;
@@ -506,7 +517,7 @@ class SystemStore extends EventEmitter {
506
517
}
507
518
} ;
508
519
await db_client . instance ( ) . connect ( ) ;
509
- await P . map ( COLLECTIONS , async col => {
520
+ await P . map_with_concurrency ( this . READ_NEW_DATA_CONCURRENCY , COLLECTIONS , async col => {
510
521
const res = await db_client . instance ( ) . collection ( col . name )
511
522
. find ( newly_updated_query , {
512
523
projection : { last_update : 0 }
0 commit comments