Skip to content

Commit

Permalink
improve logic of image cache
Browse files Browse the repository at this point in the history
  • Loading branch information
timonegk committed Mar 30, 2021
1 parent 75a9b39 commit 7f7163f
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -987,11 +987,14 @@ function calculateImageScale() {
async function preloadImages() {
let keepImages = [];
let cacheLoadings = [];
for (let imageId = gImageId - PRELOAD_BACKWARD;
imageId <= gImageId + PRELOAD_FORWARD;
imageId++) {
keepImages.push(imageId);
cacheLoadings.push(loadImageToCache(imageId));
let currentImageIndex = gImageList.indexOf(gImageId);
for (let index = currentImageIndex - PRELOAD_BACKWARD;
index <= currentImageIndex + PRELOAD_FORWARD;
index++) {
if (gImageList[index] !== undefined) {
keepImages.push(gImageList[index]);
cacheLoadings.push(loadImageToCache(gImageList[index]));
}
}
await Promise.all(cacheLoadings);
pruneImageCache(keepImages);
Expand Down

0 comments on commit 7f7163f

Please sign in to comment.