Skip to content

Commit

Permalink
refactor: use object not array for helm cache (#8733)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Feb 17, 2021
1 parent 641e95e commit 720907e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/datasource/helm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export const defaultConfig = {
},
};

export type RepositoryData = Record<string, ReleaseResult>;

export async function getRepositoryData(
repository: string
): Promise<ReleaseResult[]> {
): Promise<RepositoryData> {
const cacheNamespace = 'datasource-helm';
const cacheKey = repository;
const cachedIndex = await packageCache.get<ReleaseResult[]>(
const cachedIndex = await packageCache.get<RepositoryData>(
cacheNamespace,
cacheKey
);
Expand Down Expand Up @@ -73,17 +75,18 @@ export async function getRepositoryData(
logger.warn(`Failed to parse index.yaml from ${repository}`);
return null;
}
const result: ReleaseResult[] = Object.entries(doc.entries).map(
([name, releases]): ReleaseResult => ({
const result: RepositoryData = {};
for (const [name, releases] of Object.entries(doc.entries)) {
result[name] = {
name,
homepage: releases[0].home,
sourceUrl: releases[0].sources ? releases[0].sources[0] : undefined,
releases: releases.map((release) => ({
version: release.version,
releaseTimestamp: release.created ? release.created : null,
})),
})
);
};
}
const cacheMinutes = 20;
await packageCache.set(cacheNamespace, cacheKey, result, cacheMinutes);
return result;
Expand All @@ -103,7 +106,7 @@ export async function getReleases({
logger.debug(`Couldn't get index.yaml file from ${helmRepository}`);
return null;
}
const releases = repositoryData.find((chart) => chart.name === lookupName);
const releases = repositoryData[lookupName];
if (!releases) {
logger.debug(
{ dependency: lookupName },
Expand Down

0 comments on commit 720907e

Please sign in to comment.