diff --git a/src/utils/work/dispatchWorkRequest.js b/src/utils/work/dispatchWorkRequest.js index 6f48d7214c..cdcc78f758 100644 --- a/src/utils/work/dispatchWorkRequest.js +++ b/src/utils/work/dispatchWorkRequest.js @@ -1,6 +1,25 @@ import dayjs from 'dayjs'; +import { Environment } from 'utils/deploymentInfo'; import fetchAPI from 'utils/http/fetchAPI'; +// Disable unique keys to reallow reuse of work results in development +const DISABLE_UNIQUE_KEYS = [ + 'GetEmbedding', +]; + +const getCacheUniquenessKey = (taskName, environment) => { + // Disable cache in development or if localStorage says so + // Do not disable for embeddings requests because download seurat & trajectory depend on that ETag + if ( + environment !== Environment.PRODUCTION + && (localStorage.getItem('disableCache') === 'true' || environment === Environment.DEVELOPMENT) + && !DISABLE_UNIQUE_KEYS.includes(taskName) + ) { + return Math.random(); + } + + return null; +}; const getWorkerTimeout = (taskName, defaultTimeout) => { switch (taskName) { @@ -21,6 +40,7 @@ const dispatchWorkRequest = async ( body, timeout, requestProps, + getState, ) => { const { name: taskName } = body; @@ -32,11 +52,18 @@ const dispatchWorkRequest = async ( // this should be removed if we make each request run in a different worker const workerTimeoutDate = getWorkerTimeout(taskName, timeout); + const { environment } = getState().networkResources; + const cacheUniquenessKey = getCacheUniquenessKey(taskName, environment); + + // eslint-disable-next-line no-param-reassign + requestProps.cacheUniquenessKey = cacheUniquenessKey; + const request = { experimentId, timeout: workerTimeoutDate, body, - ...requestProps, + requestProps, + }; const { data: { ETag, signedUrl } } = await fetchAPI( diff --git a/src/utils/work/fetchWork.js b/src/utils/work/fetchWork.js index db561462ec..6e0bf00f1b 100644 --- a/src/utils/work/fetchWork.js +++ b/src/utils/work/fetchWork.js @@ -1,4 +1,4 @@ -import { Environment, isBrowser } from 'utils/deploymentInfo'; +import { isBrowser } from 'utils/deploymentInfo'; import cache from 'utils/cache'; import dispatchWorkRequest from 'utils/work/dispatchWorkRequest'; @@ -68,11 +68,6 @@ const fetchWork = async ( throw new Error('Disabling network interaction on server'); } - const { environment } = getState().networkResources; - if (environment === Environment.DEVELOPMENT && !localStorage.getItem('disableCache')) { - localStorage.setItem('disableCache', 'true'); - } - // 1. Contact the API to get ETag and possible S3 signedURL const { ETag, signedUrl, request } = await dispatchWorkRequest( experimentId, @@ -82,7 +77,7 @@ const fetchWork = async ( broadcast, ...extras, }, - dispatch, + getState, ); onETagGenerated(ETag);