From 9482a3dcf44db9c0d39234f7b1aafcfebcc3d897 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 12 Dec 2022 10:36:35 +0100 Subject: [PATCH] improve preloading --- packages/web-app-preview/src/App.vue | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/web-app-preview/src/App.vue b/packages/web-app-preview/src/App.vue index 3631a420996..9b170361693 100644 --- a/packages/web-app-preview/src/App.vue +++ b/packages/web-app-preview/src/App.vue @@ -564,22 +564,36 @@ export default defineComponent({ }) } - console.log('active index: ', this.activeIndex) + const preloadUpcomingFile = (upcomingFileIndex) => { + let cycleIndex = + (((this.activeIndex + upcomingFileIndex) % this.filteredFiles.length) + + this.filteredFiles.length) % + this.filteredFiles.length - for ( - let followingFileIndex = 1; - followingFileIndex <= PRELOAD_IMAGE_COUNT; - followingFileIndex++ - ) { - let cycleIndex = (this.activeIndex + followingFileIndex) % this.activeFiles.length const file = this.filteredFiles[cycleIndex] if (!this.isFileTypeImage(file) || toPreloadFiles.includes(file.id)) { - continue + return } loadPreviewAsync(file) } + + for ( + let followingFileIndex = 1; + followingFileIndex <= PRELOAD_IMAGE_COUNT; + followingFileIndex++ + ) { + preloadUpcomingFile(followingFileIndex) + } + + for ( + let previousFileIndex = -1; + previousFileIndex >= PRELOAD_IMAGE_COUNT * -1; + previousFileIndex-- + ) { + preloadUpcomingFile(previousFileIndex) + } } } })