Skip to content

Commit

Permalink
fix: optimize cache data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Jan 24, 2024
1 parent 3049d45 commit 6a2a7d7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/home/fetch-github/fetch-and-display-previews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down
12 changes: 4 additions & 8 deletions src/home/rendering/render-github-issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,15 @@ function setUpIssueElement(
) {
let image = `<img />`;

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 = `<img src="${avatarUrl}" />`;
}

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 = `<img src="${avatarUrl}" />`;
}
const avatarUrl = URL.createObjectURL(avatarBlob);
image = `<img src="${avatarUrl}" />`;
}

issueElement.innerHTML = `
Expand Down

0 comments on commit 6a2a7d7

Please sign in to comment.