Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: StackPrefetch should use the imageLoadPoolManager #1433

Merged
merged 2 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
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
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