Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cache): distinguish between null and undefined #6509

Merged
merged 1 commit into from Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/datasource/cache.ts
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
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
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 @@ -495,7 +495,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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated, but okay 🙃

const hostStats: string[] = [];
let totalRequests = 0;
for (const [hostname, requests] of Object.entries(requestHosts)) {
Expand Down