Skip to content

Commit

Permalink
fix cache types
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee committed Oct 3, 2020
1 parent 7c7c088 commit b0fa1aa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions lib/datasource/index.ts
Expand Up @@ -220,10 +220,10 @@ function getRawReleases(
registryUrls
)}`;
// By returning a Promise and reusing it, we should only fetch each package at most once
const cachedResult = memCache.get<ReleaseResult>(cacheKey);
const cachedResult = memCache.get<Promise<ReleaseResult | null>>(cacheKey);
// istanbul ignore if
if (cachedResult) {
return Promise.resolve(cachedResult);
if (cachedResult !== undefined) {
return cachedResult;
}
const promisedRes = fetchReleases(config);
memCache.set(cacheKey, promisedRes);
Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/packagist/index.ts
Expand Up @@ -204,10 +204,10 @@ async function getAllPackages(regUrl: string): Promise<AllPackages | null> {

function getAllCachedPackages(regUrl: string): Promise<AllPackages | null> {
const cacheKey = `packagist-${regUrl}`;
const cachedResult = memCache.get<AllPackages>(cacheKey);
const cachedResult = memCache.get<Promise<AllPackages | null>>(cacheKey);
// istanbul ignore if
if (cachedResult) {
return Promise.resolve(cachedResult);
if (cachedResult !== undefined) {
return cachedResult;
}
const promisedRes = getAllPackages(regUrl);
memCache.set(cacheKey, promisedRes);
Expand Down
14 changes: 7 additions & 7 deletions lib/workers/pr/changelog/release-notes.ts
Expand Up @@ -42,10 +42,10 @@ export function getCachedReleaseList(
repository: string
): Promise<ChangeLogNotes[]> {
const cacheKey = `getReleaseList-${apiBaseUrl}-${repository}`;
const cachedResult = memCache.get<ChangeLogNotes[]>(cacheKey);
const cachedResult = memCache.get<Promise<ChangeLogNotes[]>>(cacheKey);
// istanbul ignore if
if (cachedResult) {
return Promise.resolve(cachedResult);
if (cachedResult !== undefined) {
return cachedResult;
}
const promisedRes = getReleaseList(apiBaseUrl, repository);
memCache.set(cacheKey, promisedRes);
Expand Down Expand Up @@ -179,12 +179,12 @@ export async function getReleaseNotesMdFileInner(
export function getReleaseNotesMdFile(
repository: string,
apiBaseUrl: string
): Promise<ChangeLogFile> | null {
): Promise<ChangeLogFile | null> {
const cacheKey = `getReleaseNotesMdFile-${repository}-${apiBaseUrl}`;
const cachedResult = memCache.get<ChangeLogFile>(cacheKey);
const cachedResult = memCache.get<Promise<ChangeLogFile | null>>(cacheKey);
// istanbul ignore if
if (cachedResult) {
return Promise.resolve(cachedResult);
if (cachedResult !== undefined) {
return cachedResult;
}
const promisedRes = getReleaseNotesMdFileInner(repository, apiBaseUrl);
memCache.set(cacheKey, promisedRes);
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/pr/changelog/source-github.ts
Expand Up @@ -16,10 +16,10 @@ function getCachedTags(
repository: string
): Promise<string[]> {
const cacheKey = `getTags-${endpoint}-${repository}`;
const cachedResult = memCache.get<string[]>(cacheKey);
const cachedResult = memCache.get<Promise<string[]>>(cacheKey);
// istanbul ignore if
if (cachedResult) {
return Promise.resolve(cachedResult);
if (cachedResult !== undefined) {
return cachedResult;
}
const promisedRes = getTags(endpoint, repository);
memCache.set(cacheKey, promisedRes);
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/pr/changelog/source-gitlab.ts
Expand Up @@ -18,10 +18,10 @@ function getCachedTags(
repository: string
): Promise<string[]> {
const cacheKey = `getTags-${endpoint}-${versionScheme}-${repository}`;
const cachedResult = memCache.get<string[]>(cacheKey);
const cachedResult = memCache.get<Promise<string[]>>(cacheKey);
// istanbul ignore if
if (cachedResult) {
return Promise.resolve(cachedResult);
if (cachedResult !== undefined) {
return cachedResult;
}
const promisedRes = getTags(endpoint, repository);
memCache.set(cacheKey, promisedRes);
Expand Down

0 comments on commit b0fa1aa

Please sign in to comment.