From a9a3203c1c41e2c990f608ad6a994056dbd6ece3 Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Mon, 23 Sep 2024 19:22:19 +0200 Subject: [PATCH 1/2] speedup Library.LibGetAllLibStorageKeys() --- plugin/js/Library.js | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/plugin/js/Library.js b/plugin/js/Library.js index 1e523b00..406d2699 100644 --- a/plugin/js/Library.js +++ b/plugin/js/Library.js @@ -14,7 +14,7 @@ class Library { document.getElementById("includeInReadingListCheckbox").click(); } chrome.storage.local.get(null, async function(items) { - let CurrentLibStoryURLKeys = await Library.LibGetAllLibStorageKeys("LibStoryURL"); + let CurrentLibStoryURLKeys = await Library.LibGetAllLibStorageKeys("LibStoryURL", Object.keys(items)); let LibidURL = -1; for (let i = 0; i < CurrentLibStoryURLKeys.length; i++) { if (items[CurrentLibStoryURLKeys[i]] == document.getElementById("startingUrlInput").value) { @@ -242,7 +242,7 @@ class Library { static Libdeleteall(){ chrome.storage.local.get(null, async function(items) { - let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub"); + let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items)); let storyurls = []; for (let i = 0; i < CurrentLibKeys.length; i++) { CurrentLibKeys[i] = CurrentLibKeys[i].replace("LibEpub",""); @@ -261,9 +261,10 @@ class Library { } static LibRenderSavedEpubs(){ + var startTime = performance.now() chrome.storage.local.get(null, async function(items) { let ShowAdvancedOptions = document.getElementById("LibShowAdvancedOptionsCheckbox").checked; - let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub"); + let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items)); let LibRenderResult = document.getElementById("LibRenderResult"); let LibRenderString = ""; let LibTemplateDeleteEpub = document.getElementById("LibTemplateDeleteEpub").innerHTML; @@ -375,6 +376,8 @@ class Library { for (let i = 0; i < CurrentLibKeys.length; i++) { document.getElementById("LibCover"+CurrentLibKeys[i]).src = await items["LibCover" + CurrentLibKeys[i]]; } + var endTime = performance.now() + console.log(`Call to doSomething took ${endTime - startTime} milliseconds`) }); } @@ -682,7 +685,7 @@ class Library { static Libexportall(){ chrome.storage.local.get(null, async function(items) { - let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub"); + let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items)); var retobj = {}; retobj.Library = []; for (let i = 0; i < CurrentLibKeys.length; i++) { @@ -762,18 +765,28 @@ class Library { document.getElementById("LibURLWarning"+obj.dataset.libepubid).innerHTML = ""; } - static async LibGetAllLibStorageKeys(Substring){ + static async LibGetAllLibStorageKeys(Substring, AllStorageKeysList){ return new Promise((resolve) => { - chrome.storage.local.get(null, function(items){ - let AllStorageKeys = Object.keys(items); + if (AllStorageKeysList == undefined) { + chrome.storage.local.get(null, function(items){ + let AllStorageKeys = Object.keys(items); + let AllLibStorageKeys = []; + for (let i = 0, end = AllStorageKeys.length; i < end; i++) { + if(AllStorageKeys[i].includes(Substring)){ + AllLibStorageKeys.push(AllStorageKeys[i]); + } + } + resolve(AllLibStorageKeys); + }); + } else { let AllLibStorageKeys = []; - for (let i = 0, end = AllStorageKeys.length; i < end; i++) { - if(AllStorageKeys[i].includes(Substring)){ - AllLibStorageKeys.push(AllStorageKeys[i]); + for (let i = 0, end = AllStorageKeysList.length; i < end; i++) { + if(AllStorageKeysList[i].includes(Substring)){ + AllLibStorageKeys.push(AllStorageKeysList[i]); } } resolve(AllLibStorageKeys); - }); + } }); } From 317bbeeee2872f2b894c8072468250a41112433f Mon Sep 17 00:00:00 2001 From: gamebeaker Date: Mon, 23 Sep 2024 19:28:28 +0200 Subject: [PATCH 2/2] remove time meassurement of LibRenderSavedEpubs() --- plugin/js/Library.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugin/js/Library.js b/plugin/js/Library.js index 406d2699..51013ddf 100644 --- a/plugin/js/Library.js +++ b/plugin/js/Library.js @@ -261,7 +261,6 @@ class Library { } static LibRenderSavedEpubs(){ - var startTime = performance.now() chrome.storage.local.get(null, async function(items) { let ShowAdvancedOptions = document.getElementById("LibShowAdvancedOptionsCheckbox").checked; let CurrentLibKeys = await Library.LibGetAllLibStorageKeys("LibEpub", Object.keys(items)); @@ -376,8 +375,6 @@ class Library { for (let i = 0; i < CurrentLibKeys.length; i++) { document.getElementById("LibCover"+CurrentLibKeys[i]).src = await items["LibCover" + CurrentLibKeys[i]]; } - var endTime = performance.now() - console.log(`Call to doSomething took ${endTime - startTime} milliseconds`) }); }