From 7f7163f75a93d0be1997e77be48ba905156d74bd Mon Sep 17 00:00:00 2001 From: Timon Engelke Date: Tue, 30 Mar 2021 17:19:31 +0200 Subject: [PATCH] improve logic of image cache --- .../static/annotations/js/annotations.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/imagetagger/imagetagger/annotations/static/annotations/js/annotations.js b/imagetagger/imagetagger/annotations/static/annotations/js/annotations.js index 74e205dd..c68707d4 100644 --- a/imagetagger/imagetagger/annotations/static/annotations/js/annotations.js +++ b/imagetagger/imagetagger/annotations/static/annotations/js/annotations.js @@ -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);