Skip to content

Commit 3049d45

Browse files
committed
chore: optimize cache data structure
1 parent e54d162 commit 3049d45

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/home/fetch-github/fetch-avatar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { organizationImageCache } from "./fetch-issues-full";
55

66
export async function fetchAvatar(orgName: string) {
77
// Check local cache first
8-
const cachedAvatar = organizationImageCache.find((entry) => entry[orgName] !== undefined);
8+
const cachedAvatar = organizationImageCache.get(orgName);
99
if (cachedAvatar) {
1010
return Promise.resolve();
1111
}
@@ -14,7 +14,7 @@ export async function fetchAvatar(orgName: string) {
1414
const avatarBlob = await getImageFromDB({ dbName: "ImageDatabase", storeName: "ImageStore", orgName: `avatarUrl-${orgName}` });
1515
if (avatarBlob) {
1616
// If the avatar Blob is found in IndexedDB, add it to the cache
17-
organizationImageCache.push({ [orgName]: avatarBlob });
17+
organizationImageCache.set(orgName, avatarBlob);
1818
return Promise.resolve();
1919
}
2020

@@ -35,11 +35,11 @@ export async function fetchAvatar(orgName: string) {
3535
orgName: `avatarUrl-${orgName}`,
3636
avatarBlob: blob,
3737
});
38-
organizationImageCache.push({ [orgName]: blob });
38+
organizationImageCache.set(orgName, blob);
3939
});
4040
}
4141
})
4242
.catch((error) => {
4343
console.error(`Failed to fetch avatar for organization ${orgName}: ${error}`);
4444
});
45-
}
45+
}

src/home/fetch-github/fetch-issues-full.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PreviewToFullMapping } from "./preview-to-full-mapping";
77

88
export const previewToFullMapping = new PreviewToFullMapping().getMapping();
99

10-
export const organizationImageCache = [] as { [organization: string]: Blob | null }[];
10+
export const organizationImageCache = new Map<string, Blob | null>();
1111

1212
export function fetchIssuesFull(previews: GitHubIssue[]) {
1313
const authToken = getGitHubAccessToken();

0 commit comments

Comments
 (0)