Skip to content

Commit 4f4105e

Browse files
committed
Fix cache update upon the dashboard sample update process
1 parent fa209ce commit 4f4105e

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

frontend/src/components/SamplesList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import { DataName } from "../shared/types";
4444
import { parseUserSearchVal } from "../utils/parseSearchQueries";
4545

4646
const POLLING_INTERVAL = 5000; // 5s
47+
const POLLING_PAUSE_AFTER_UPDATE = 12000; // 12s
4748

4849
const COST_CENTER_VALIDATION_ALERT =
4950
"Please update your Cost Center/Fund Number input as #####/##### (5 digits, a forward slash, then 5 digits). For example: 12345/12345.";
@@ -284,7 +285,7 @@ export default function SamplesList({
284285
setTimeout(async () => {
285286
refreshData(userSearchVal);
286287
startPolling(POLLING_INTERVAL);
287-
}, 10000);
288+
}, POLLING_PAUSE_AFTER_UPDATE);
288289

289290
handleDiscardChanges();
290291
}

graphql-server/src/utils/cache.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const WES_SAMPLE_CONTEXT = {
4343
};
4444

4545
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
4747

4848
export type OncotreeCache = Record<string, { name: string; mainType: string }>; // key = Oncotree code
4949
export type SamplesCache = Record<string, DashboardSample[]>; // key = full Cypher query
@@ -79,11 +79,9 @@ export async function initializeInMemoryCache() {
7979
inMemoryCache.on("expired", async (key) => {
8080
if (key === ONCOTREE_CACHE_KEY) {
8181
await updateOncotreeCache(inMemoryCache);
82-
logCacheStats(inMemoryCache);
8382
}
8483
if (key === SAMPLES_CACHE_KEY) {
8584
await updateSamplesCache(inMemoryCache);
86-
logCacheStats(inMemoryCache);
8785
}
8886
});
8987

@@ -224,6 +222,19 @@ export async function updateCacheWithNewSampleUpdates(
224222
inMemoryCache: NodeCache
225223
) {
226224
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+
}
227238

228239
// Create a map out of newDashboardSamples for quick lookup by primaryId
229240
const newSamplesByPrimaryId = newDashboardSamples.reduce(
@@ -268,9 +279,8 @@ export async function updateCacheWithNewSampleUpdates(
268279
}
269280
}
270281

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) {
274284
if (newSamplesByPrimaryId.hasOwnProperty(sample.primaryId)) {
275285
// Update the fields of any samples in cache that were changed in newDashboardSamples
276286
const newDashboardSample = newSamplesByPrimaryId[sample.primaryId];
@@ -280,7 +290,7 @@ export async function updateCacheWithNewSampleUpdates(
280290
newDashboardSample[field as keyof DashboardSampleInput];
281291
}
282292
}
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
284294
const latestSampleData = sampleDataForCacheUpdate[sample.primaryId];
285295
for (const [field, value] of Object.entries(latestSampleData)) {
286296
(sample as any)[field] = value;

0 commit comments

Comments
 (0)