Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 44 additions & 46 deletions web_client/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Vue.use(Vuex);
const fileCache = new Map();
const frameCache = new Map();
let readDataQueue = [];
const loadedData = [];
const pendingFrameDownloads = new Set<any>();
const poolSize = Math.floor(navigator.hardwareConcurrency / 2) || 2;
let taskRunId = -1;
Expand Down Expand Up @@ -201,32 +202,46 @@ function startReaderWorkerPool() {
});
}

// cache frames associated with scans of current experiment
function checkLoadExperiment(oldValue, newValue) {
if (
!newValue
|| newValue === oldValue
) {
return;
function queueLoadScan(scan, loadNext = false) {
// load all frames in target scan
if (!loadedData.includes(scan.id)) {
store.state.scanFrames[scan.id].forEach(
(frameId) => {
readDataQueue.push({
experimentId: scan.experiment,
scanId: scan.id,
frame: store.state.frames[frameId],
});
},
);
loadedData.push(scan.id);
}

readDataQueue = [];
const newExperimentScans = store.state.experimentScans[newValue.id];
newExperimentScans.forEach((scanId) => {
const scanFrames = store.state.scanFrames[scanId].map(
(frameId) => store.state.frames[frameId],
);
scanFrames.forEach((frame) => {
readDataQueue.push({
// TODO don't hardcode projectId
projectId: 1,
experimentId: newValue.id,
scanId,
frame,
});
});
});
startReaderWorkerPool();
// semi-recursive; we only recurse on the first call
// to queue up the next scan as well
// to prefetch further ahead, modify the recursion
if (loadNext) {
const scansInSameExperiment = store.state.experimentScans[scan.experiment];
let nextScan;
if (scan.id === scansInSameExperiment[scansInSameExperiment.length - 1]) {
// load first scan in next experiment
const experimentIds = Object.keys(store.state.experimentScans);
const nextExperimentId = experimentIds[experimentIds.indexOf(scan.experiment) + 1];
const nextExperimentScans = store.state.experimentScans[nextExperimentId];
if (nextExperimentScans && nextExperimentScans.length > 0) {
nextScan = store.state.allScans[
nextExperimentScans[0]
];
}
} else {
// load next scan in same experiment
nextScan = store.state.allScans[scansInSameExperiment[
scansInSameExperiment.indexOf(scan.id) + 1
]];
}
if (nextScan) queueLoadScan(nextScan);
startReaderWorkerPool();
}
}

// get next frame (across experiments and scans)
Expand Down Expand Up @@ -749,25 +764,11 @@ const {
commit('setErrorLoadingFrame', false);
const oldScan = getters.currentScan;
const newScan = state.scans[frame.scan];
const oldExperiment = getters.currentExperiment
? getters.currentExperiment
: null;
const newExperimentId = state.scans[frame.scan].experiment;
const newExperiment = state.experiments[newExperimentId];

// Check if we should cancel the currently loading experiment
if (
newExperiment
&& oldExperiment
&& newExperiment.id !== oldExperiment.id
&& taskRunId >= 0
) {
state.workerPool.cancel(taskRunId);
pendingFrameDownloads.forEach(({ abortController }) => {
abortController.abort();
});
pendingFrameDownloads.clear();
taskRunId = -1;

if (newScan !== oldScan && newScan) {
queueLoadScan(
newScan, true,
);
}

let newProxyManager = false;
Expand Down Expand Up @@ -828,9 +829,6 @@ const {
commit('setLoadingFrame', false);
}

// If necessary, queue loading scans of new experiment
checkLoadExperiment(oldExperiment, newExperiment);

// check for window lock expiry
if (state.windowLocked.lock) {
const { currentViewData } = getters;
Expand Down