From 6a2a7d77951b34509523f868e5b1eaaeac4061cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 24 Jan 2024 17:57:41 +0900 Subject: [PATCH] fix: optimize cache data structure --- src/home/fetch-github/fetch-and-display-previews.ts | 2 +- src/home/rendering/render-github-issues.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/home/fetch-github/fetch-and-display-previews.ts b/src/home/fetch-github/fetch-and-display-previews.ts index 75dceb14..585643ba 100644 --- a/src/home/fetch-github/fetch-and-display-previews.ts +++ b/src/home/fetch-github/fetch-and-display-previews.ts @@ -48,7 +48,7 @@ function displayIssues(issues: GitHubIssue[], container: HTMLDivElement, sorting if (orgName) { const avatarUrl = await getImageFromDB({ dbName: "ImageDatabase", storeName: "ImageStore", orgName: `avatarUrl-${orgName}` }); if (avatarUrl) { - organizationImageCache.push({ [orgName]: avatarUrl }); + organizationImageCache.set(orgName, avatarUrl); } } }); diff --git a/src/home/rendering/render-github-issues.ts b/src/home/rendering/render-github-issues.ts index 92ffd82f..6cb94200 100644 --- a/src/home/rendering/render-github-issues.ts +++ b/src/home/rendering/render-github-issues.ts @@ -69,19 +69,15 @@ function setUpIssueElement( ) { let image = ``; - const orgCacheEntry = organizationImageCache.find((entry) => Object.prototype.hasOwnProperty.call(entry, organizationName)); - const avatarUrl = orgCacheEntry ? orgCacheEntry[organizationName] : null; + const avatarUrl = organizationImageCache.get(organizationName); if (avatarUrl) { image = ``; } - const avatarBlob = organizationImageCache.find((entry) => entry[organizationName]); + const avatarBlob = organizationImageCache.get(organizationName); if (avatarBlob) { - const blob = avatarBlob[organizationName]; - if (blob) { - const avatarUrl = URL.createObjectURL(blob); - image = ``; - } + const avatarUrl = URL.createObjectURL(avatarBlob); + image = ``; } issueElement.innerHTML = `