From fdb0e47e426091d14f1f7306bc3db5a8f97c39bc Mon Sep 17 00:00:00 2001 From: Alireza Date: Fri, 1 Oct 2021 03:51:23 -0400 Subject: [PATCH] fix: StackPrefetch should use the imageLoadPoolManager (#1433) * fix: StackPrefetch should use the imageLoadPoolManager * bump cornerstone-core version Co-authored-by: swederik --- package.json | 2 +- src/stackTools/stackPrefetch.js | 38 +++++++++++++++++++++++---------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 3a7b87c3f..3fe530a09 100755 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ ] }, "peerDependencies": { - "cornerstone-core": "^2.5.0" + "cornerstone-core": "^2.6.0" }, "devDependencies": { "@babel/core": "^7.5.0", diff --git a/src/stackTools/stackPrefetch.js b/src/stackTools/stackPrefetch.js index f20736590..52459de71 100755 --- a/src/stackTools/stackPrefetch.js +++ b/src/stackTools/stackPrefetch.js @@ -9,6 +9,8 @@ const logger = getLogger('stackTools:stackPrefetch'); const toolName = 'stackPrefetch'; const requestType = 'prefetch'; +const priority = 0; +const addToBeginning = true; let configuration = { maxImagesToPrefetch: Infinity, @@ -229,18 +231,32 @@ function prefetch(element) { imageIdsToPrefetch.push(imageId); } } - // Load images in reverse order, by adding them at the beginning of the pool. - for (const imageToLoad of imageIdsToPrefetch.reverse()) { - if (preventCache) { - external.cornerstone - .loadImage(imageToLoad, { priority: 0, requestType }) - .then(doneCallback, failCallback); - } else { - external.cornerstone - .loadAndCacheImage(imageToLoad, { priority: 0, requestType }) - .then(doneCallback, failCallback); - } + + let requestFn; + const options = { + addToBeginning, + priority, + requestType, + }; + + if (preventCache) { + requestFn = id => external.cornerstone.loadImage(id, options); + } else { + requestFn = id => external.cornerstone.loadAndCacheImage(id, options); } + + imageIdsToPrefetch.forEach(imageId => { + external.cornerstone.imageLoadPoolManager.addRequest( + requestFn.bind(null, imageId), + requestType, + // Additional details + { + imageId, + }, + priority, + addToBeginning + ); + }); } function getPromiseRemovedHandler(element) {