Skip to content

Commit

Permalink
fix: StackPrefetch should use the imageLoadPoolManager (#1433)
Browse files Browse the repository at this point in the history
* fix: StackPrefetch should use the imageLoadPoolManager

* bump cornerstone-core version

Co-authored-by: swederik <[email protected]>
  • Loading branch information
sedghi and swederik authored Oct 1, 2021
1 parent 0e65ba3 commit fdb0e47
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
]
},
"peerDependencies": {
"cornerstone-core": "^2.5.0"
"cornerstone-core": "^2.6.0"
},
"devDependencies": {
"@babel/core": "^7.5.0",
Expand Down
38 changes: 27 additions & 11 deletions src/stackTools/stackPrefetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit fdb0e47

Please sign in to comment.