Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Revert "fix(cache): distinguish between null and undefined (#6509)"
This reverts commit 0345b40.
  • Loading branch information
rarkins committed Jun 17, 2020
1 parent 4b2f523 commit f5a588e
Show file tree
Hide file tree
Showing 27 changed files with 38 additions and 37 deletions.
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
return cachedResult;
}
const manifestResponse = await getManifestResponse(
Expand Down Expand Up @@ -386,7 +386,7 @@ async function getTags(
cacheKey
);
// istanbul ignore if
if (cachedResult !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
return cachedResult;
}
try {
Expand Down
11 changes: 7 additions & 4 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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
return cachedResult;
}
let digest: string;
Expand All @@ -95,14 +95,17 @@ 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 || null;
return digest;
}

/**
Expand All @@ -124,7 +127,7 @@ export async function getReleases({
getCacheKey(repo, 'tags')
);
// istanbul ignore if
if (cachedResult !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedIndex) {
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 !== undefined) {
if (cachedVersions) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
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 !== undefined) {
if (cachedResult) {
return cachedResult;
}
try {
Expand Down
8 changes: 3 additions & 5 deletions lib/util/cache/global/file.spec.ts
Expand Up @@ -6,10 +6,8 @@ describe('lib/util/cache/global/file', () => {
init(os.tmpdir());
});

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

it('sets and gets', async () => {
Expand All @@ -19,6 +17,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')).toBeUndefined();
expect(await global.renovateCache.get('test', 'key')).toBeNull();
});
});
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 undefined;
return null;
}

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 === undefined) {
if (!releaseNotes) {
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 || null,
releaseNotes,
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 === undefined) {
if (!release) {
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 === undefined) {
if (!release) {
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.debug({ allRequests, requestHosts }, 'full stats');
logger.trace({ allRequests, requestHosts }, 'full stats');
const hostStats: string[] = [];
let totalRequests = 0;
for (const [hostname, requests] of Object.entries(requestHosts)) {
Expand Down

0 comments on commit f5a588e

Please sign in to comment.