Skip to content

Commit

Permalink
fix(cache): distinguish between null and undefined (#6509)
Browse files Browse the repository at this point in the history
null = this lookup returned nothing last time
undefined = no cached result found
  • Loading branch information
rarkins authored Jun 17, 2020
1 parent 8ac8f42 commit 0345b40
Show file tree
Hide file tree
Showing 27 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion lib/datasource/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function cacheAble<TArg, TResult = unknown>({
const cacheKey = JSON.stringify(lookup);
const cachedResult = await globalCache.get<TResult>(cacheNamespace, cacheKey);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
logger.trace({ id, lookup }, 'datasource cachedResult');
return cachedResult;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/crate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getReleases({
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/datasource/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export async function getDigest(
const cacheKey = `${registry}:${repository}:${newTag}`;
const cachedResult = await globalCache.get(cacheNamespace, cacheKey);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
const manifestResponse = await getManifestResponse(
Expand Down Expand Up @@ -386,7 +386,7 @@ async function getTags(
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
// AWS ECR limits the maximum number of results to 1000
Expand Down Expand Up @@ -486,7 +486,7 @@ async function getLabels(
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/galaxy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getReleases({
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/git-refs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function getRawRefs({
lookupName
);
/* istanbul ignore next line */
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/git-submodules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getReleases({
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/github-releases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getReleases({
repo
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
11 changes: 4 additions & 7 deletions lib/datasource/github-tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function getTagCommit(
getCacheKey(githubRepo, `tag-${tag}`)
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
let digest: string;
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function getDigest(
getCacheKey(githubRepo, 'commit')
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
let digest: string;
Expand All @@ -95,17 +95,14 @@ export async function getDigest(
'Error getting latest commit from GitHub repo'
);
}
if (!digest) {
return null;
}
const cacheMinutes = 10;
await globalCache.set(
cacheNamespace,
getCacheKey(githubRepo, 'commit'),
digest,
cacheMinutes
);
return digest;
return digest || null;
}

/**
Expand All @@ -127,7 +124,7 @@ export async function getReleases({
getCacheKey(repo, 'tags')
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/gitlab-tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function getReleases({
getCacheKey(depHost, repo)
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/helm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getRepositoryData(
const cacheKey = repository;
const cachedIndex = await globalCache.get(cacheNamespace, cacheKey);
// istanbul ignore if
if (cachedIndex) {
if (cachedIndex !== undefined) {
return cachedIndex;
}
let res: any;
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/maven/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async function getVersionsFromMetadata(
cacheKey
);
/* istanbul ignore if */
if (cachedVersions) {
if (cachedVersions !== undefined) {
return cachedVersions;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/npm/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export async function getDependency(
pkgUrl
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
const headers: OutgoingHttpHeaders = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/nuget/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function getQueryUrl(url: string): Promise<string | null> {
const cachedResult = await globalCache.get<string>(cacheNamespace, cacheKey);

// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/orb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function getReleases({
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
const url = 'https://circleci.com/graphql-unstable';
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/packagist/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ async function packagistOrgLookup(name: string): Promise<ReleaseResult> {
name
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
let dep: ReleaseResult = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/pod/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function getReleases({
podName
);
/* istanbul ignore next line */
if (cachedResult) {
if (cachedResult !== undefined) {
logger.debug(`CocoaPods: Return cached result for ${podName}`);
return cachedResult;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/repology/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function getCachedPackage(
cacheKey
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/ruby-version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getReleases(
'all'
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/terraform-module/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export async function getReleases({
pkgUrl
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource/terraform-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function getReleases({
pkgUrl
);
// istanbul ignore if
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/manager/bazel/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function getHashFromUrl(url: string): Promise<string | null> {
url
);
/* istanbul ignore next line */
if (cachedResult) {
if (cachedResult !== undefined) {
return cachedResult;
}
try {
Expand Down
8 changes: 5 additions & 3 deletions lib/util/cache/global/file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ describe('lib/util/cache/global/file', () => {
init(os.tmpdir());
});

it('gets null', async () => {
expect(await global.renovateCache.get('test', 'missing-key')).toBeNull();
it('returns undefined if no match', async () => {
expect(
await global.renovateCache.get('test', 'missing-key')
).toBeUndefined();
});

it('sets and gets', async () => {
Expand All @@ -17,6 +19,6 @@ describe('lib/util/cache/global/file', () => {

it('expires', async () => {
await global.renovateCache.set('test', 'key', 1234, -5);
expect(await global.renovateCache.get('test', 'key')).toBeNull();
expect(await global.renovateCache.get('test', 'key')).toBeUndefined();
});
});
2 changes: 1 addition & 1 deletion lib/util/cache/global/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
} catch (err) {
logger.trace({ namespace, key }, 'Cache miss');
}
return null;
return undefined;
}

async function set(
Expand Down
4 changes: 2 additions & 2 deletions lib/workers/pr/changelog/release-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export async function addReleaseNotes(
let releaseNotes: ChangeLogNotes;
const cacheKey = getCacheKey(v.version);
releaseNotes = await globalCache.get(cacheNamespace, cacheKey);
if (!releaseNotes) {
if (releaseNotes === undefined) {
if (input.project.github != null) {
releaseNotes = await getReleaseNotesMd(
repository,
Expand Down Expand Up @@ -388,7 +388,7 @@ export async function addReleaseNotes(
await globalCache.set(
cacheNamespace,
cacheKey,
releaseNotes,
releaseNotes || null,
cacheMinutes
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/pr/changelog/source-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export async function getChangeLogJSON({
getCacheKey(prev.version, next.version)
);
// istanbul ignore else
if (!release) {
if (release === undefined) {
release = {
version: next.version,
date: next.releaseTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/pr/changelog/source-gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function getChangeLogJSON({
cacheNamespace,
getCacheKey(prev.version, next.version)
);
if (!release) {
if (release === undefined) {
release = {
version: next.version,
date: next.releaseTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function printRequestStats(): void {
requestHosts[hostname] = requestHosts[hostname] || [];
requestHosts[hostname].push(request.duration);
}
logger.trace({ allRequests, requestHosts }, 'full stats');
logger.debug({ allRequests, requestHosts }, 'full stats');
const hostStats: string[] = [];
let totalRequests = 0;
for (const [hostname, requests] of Object.entries(requestHosts)) {
Expand Down

0 comments on commit 0345b40

Please sign in to comment.