@@ -43,7 +43,7 @@ const WES_SAMPLE_CONTEXT = {
43
43
} ;
44
44
45
45
const MAX_RETRIES_UPON_FALSE_SAMPLE_STATUS = 3 ;
46
- const RETRY_INTERVAL_UPON_FALSE_SAMPLE_STATUS = 10000 ; // 10s
46
+ const RETRY_INTERVAL_UPON_FALSE_SAMPLE_STATUS = 3000 ; // 3s
47
47
48
48
export type OncotreeCache = Record < string , { name : string ; mainType : string } > ; // key = Oncotree code
49
49
export type SamplesCache = Record < string , DashboardSample [ ] > ; // key = full Cypher query
@@ -79,11 +79,9 @@ export async function initializeInMemoryCache() {
79
79
inMemoryCache . on ( "expired" , async ( key ) => {
80
80
if ( key === ONCOTREE_CACHE_KEY ) {
81
81
await updateOncotreeCache ( inMemoryCache ) ;
82
- logCacheStats ( inMemoryCache ) ;
83
82
}
84
83
if ( key === SAMPLES_CACHE_KEY ) {
85
84
await updateSamplesCache ( inMemoryCache ) ;
86
- logCacheStats ( inMemoryCache ) ;
87
85
}
88
86
} ) ;
89
87
@@ -224,6 +222,19 @@ export async function updateCacheWithNewSampleUpdates(
224
222
inMemoryCache : NodeCache
225
223
) {
226
224
const samplesCache = inMemoryCache . get ( SAMPLES_CACHE_KEY ) as SamplesCache ;
225
+ const cachedSamples = Object . values ( samplesCache ) . flat ( ) ;
226
+
227
+ // Early return if no samples in the cache are receiving updates
228
+ const cachedPrimaryIds = new Set ( cachedSamples . map ( ( s ) => s . primaryId ) ) ;
229
+ const cacheNeedsUpdate = newDashboardSamples . some ( ( s ) =>
230
+ cachedPrimaryIds . has ( s . primaryId )
231
+ ) ;
232
+ if ( ! cacheNeedsUpdate ) {
233
+ console . info (
234
+ "Skipping cache update because updated dashboard samples are not in cache."
235
+ ) ;
236
+ return ;
237
+ }
227
238
228
239
// Create a map out of newDashboardSamples for quick lookup by primaryId
229
240
const newSamplesByPrimaryId = newDashboardSamples . reduce (
@@ -268,9 +279,8 @@ export async function updateCacheWithNewSampleUpdates(
268
279
}
269
280
}
270
281
271
- // TODO: pause polling interval upon sample update
272
- console . info ( "Updating cache..." ) ;
273
- for ( const sample of Object . values ( samplesCache ) . flat ( ) ) {
282
+ console . info ( "Updating the samples cache with dashboard updates..." ) ;
283
+ for ( const sample of cachedSamples ) {
274
284
if ( newSamplesByPrimaryId . hasOwnProperty ( sample . primaryId ) ) {
275
285
// Update the fields of any samples in cache that were changed in newDashboardSamples
276
286
const newDashboardSample = newSamplesByPrimaryId [ sample . primaryId ] ;
@@ -280,7 +290,7 @@ export async function updateCacheWithNewSampleUpdates(
280
290
newDashboardSample [ field as keyof DashboardSampleInput ] ;
281
291
}
282
292
}
283
- // Update these fields of samples in cache with the latest data from Neo4j
293
+ // Update select fields of samples in cache with the latest data from Neo4j
284
294
const latestSampleData = sampleDataForCacheUpdate [ sample . primaryId ] ;
285
295
for ( const [ field , value ] of Object . entries ( latestSampleData ) ) {
286
296
( sample as any ) [ field ] = value ;
0 commit comments