From 0345b40a181134236d65ccebd450efd46700deb9 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Wed, 17 Jun 2020 06:48:33 +0200 Subject: [PATCH] fix(cache): distinguish between null and undefined (#6509) null = this lookup returned nothing last time undefined = no cached result found --- lib/datasource/cache.ts | 2 +- lib/datasource/crate/index.ts | 2 +- lib/datasource/docker/index.ts | 6 +++--- lib/datasource/galaxy/index.ts | 2 +- lib/datasource/git-refs/index.ts | 2 +- lib/datasource/git-submodules/index.ts | 2 +- lib/datasource/github-releases/index.ts | 2 +- lib/datasource/github-tags/index.ts | 11 ++++------- lib/datasource/gitlab-tags/index.ts | 2 +- lib/datasource/helm/index.ts | 2 +- lib/datasource/maven/index.ts | 2 +- lib/datasource/npm/get.ts | 2 +- lib/datasource/nuget/v3.ts | 2 +- lib/datasource/orb/index.ts | 2 +- lib/datasource/packagist/index.ts | 2 +- lib/datasource/pod/index.ts | 2 +- lib/datasource/repology/index.ts | 2 +- lib/datasource/ruby-version/index.ts | 2 +- lib/datasource/terraform-module/index.ts | 2 +- lib/datasource/terraform-provider/index.ts | 2 +- lib/manager/bazel/update.ts | 2 +- lib/util/cache/global/file.spec.ts | 8 +++++--- lib/util/cache/global/file.ts | 2 +- lib/workers/pr/changelog/release-notes.ts | 4 ++-- lib/workers/pr/changelog/source-github.ts | 2 +- lib/workers/pr/changelog/source-gitlab.ts | 2 +- lib/workers/repository/stats.ts | 2 +- 27 files changed, 37 insertions(+), 38 deletions(-) diff --git a/lib/datasource/cache.ts b/lib/datasource/cache.ts index ecd74cbe79e176..f0ad5eaa3198e2 100644 --- a/lib/datasource/cache.ts +++ b/lib/datasource/cache.ts @@ -60,7 +60,7 @@ export async function cacheAble({ const cacheKey = JSON.stringify(lookup); const cachedResult = await globalCache.get(cacheNamespace, cacheKey); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { logger.trace({ id, lookup }, 'datasource cachedResult'); return cachedResult; } diff --git a/lib/datasource/crate/index.ts b/lib/datasource/crate/index.ts index fe948c1ab79079..e8e64eba5eef4d 100644 --- a/lib/datasource/crate/index.ts +++ b/lib/datasource/crate/index.ts @@ -22,7 +22,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index 9ab3c01480fad5..0317e4927b2e41 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -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( @@ -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 @@ -486,7 +486,7 @@ async function getLabels( cacheKey ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/datasource/galaxy/index.ts b/lib/datasource/galaxy/index.ts index ce6b9e89643596..b49eca902d18a5 100644 --- a/lib/datasource/galaxy/index.ts +++ b/lib/datasource/galaxy/index.ts @@ -22,7 +22,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/git-refs/index.ts b/lib/datasource/git-refs/index.ts index afd75aed8c0bd0..4b608589da1be9 100644 --- a/lib/datasource/git-refs/index.ts +++ b/lib/datasource/git-refs/index.ts @@ -29,7 +29,7 @@ export async function getRawRefs({ lookupName ); /* istanbul ignore next line */ - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/git-submodules/index.ts b/lib/datasource/git-submodules/index.ts index b00fe9afa52dd4..bf0dbfda00c943 100644 --- a/lib/datasource/git-submodules/index.ts +++ b/lib/datasource/git-submodules/index.ts @@ -18,7 +18,7 @@ export async function getReleases({ cacheKey ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/github-releases/index.ts b/lib/datasource/github-releases/index.ts index 8b4c2c89dcd503..621a5b0f446d56 100644 --- a/lib/datasource/github-releases/index.ts +++ b/lib/datasource/github-releases/index.ts @@ -33,7 +33,7 @@ export async function getReleases({ repo ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/datasource/github-tags/index.ts b/lib/datasource/github-tags/index.ts index fea2bae705bd85..6f5ce1689fb140 100644 --- a/lib/datasource/github-tags/index.ts +++ b/lib/datasource/github-tags/index.ts @@ -29,7 +29,7 @@ async function getTagCommit( getCacheKey(githubRepo, `tag-${tag}`) ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } let digest: string; @@ -81,7 +81,7 @@ export async function getDigest( getCacheKey(githubRepo, 'commit') ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } let digest: string; @@ -95,9 +95,6 @@ export async function getDigest( 'Error getting latest commit from GitHub repo' ); } - if (!digest) { - return null; - } const cacheMinutes = 10; await globalCache.set( cacheNamespace, @@ -105,7 +102,7 @@ export async function getDigest( digest, cacheMinutes ); - return digest; + return digest || null; } /** @@ -127,7 +124,7 @@ export async function getReleases({ getCacheKey(repo, 'tags') ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/datasource/gitlab-tags/index.ts b/lib/datasource/gitlab-tags/index.ts index 15411d83cf8c0c..93f5169b642307 100644 --- a/lib/datasource/gitlab-tags/index.ts +++ b/lib/datasource/gitlab-tags/index.ts @@ -35,7 +35,7 @@ export async function getReleases({ getCacheKey(depHost, repo) ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/helm/index.ts b/lib/datasource/helm/index.ts index d646d07d2178fd..06854b78883348 100644 --- a/lib/datasource/helm/index.ts +++ b/lib/datasource/helm/index.ts @@ -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; diff --git a/lib/datasource/maven/index.ts b/lib/datasource/maven/index.ts index 99efb384dde0ef..d381e81472120e 100644 --- a/lib/datasource/maven/index.ts +++ b/lib/datasource/maven/index.ts @@ -162,7 +162,7 @@ async function getVersionsFromMetadata( cacheKey ); /* istanbul ignore if */ - if (cachedVersions) { + if (cachedVersions !== undefined) { return cachedVersions; } diff --git a/lib/datasource/npm/get.ts b/lib/datasource/npm/get.ts index d2f0e2ab362cc6..9caed7b5d1a82c 100644 --- a/lib/datasource/npm/get.ts +++ b/lib/datasource/npm/get.ts @@ -75,7 +75,7 @@ export async function getDependency( pkgUrl ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } const headers: OutgoingHttpHeaders = {}; diff --git a/lib/datasource/nuget/v3.ts b/lib/datasource/nuget/v3.ts index 507af6cbea3542..cec3735a4fce7c 100644 --- a/lib/datasource/nuget/v3.ts +++ b/lib/datasource/nuget/v3.ts @@ -24,7 +24,7 @@ export async function getQueryUrl(url: string): Promise { const cachedResult = await globalCache.get(cacheNamespace, cacheKey); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/orb/index.ts b/lib/datasource/orb/index.ts index 0d54db74e9217f..cb5d4aefdf197d 100644 --- a/lib/datasource/orb/index.ts +++ b/lib/datasource/orb/index.ts @@ -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'; diff --git a/lib/datasource/packagist/index.ts b/lib/datasource/packagist/index.ts index 73d8d3e238ff7b..365990dabdc527 100644 --- a/lib/datasource/packagist/index.ts +++ b/lib/datasource/packagist/index.ts @@ -236,7 +236,7 @@ async function packagistOrgLookup(name: string): Promise { name ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } let dep: ReleaseResult = null; diff --git a/lib/datasource/pod/index.ts b/lib/datasource/pod/index.ts index ce957dad14780c..d4dfe7ede82fcf 100644 --- a/lib/datasource/pod/index.ts +++ b/lib/datasource/pod/index.ts @@ -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; } diff --git a/lib/datasource/repology/index.ts b/lib/datasource/repology/index.ts index e45c10f021ed23..d0c144354df5d5 100644 --- a/lib/datasource/repology/index.ts +++ b/lib/datasource/repology/index.ts @@ -89,7 +89,7 @@ async function getCachedPackage( cacheKey ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } diff --git a/lib/datasource/ruby-version/index.ts b/lib/datasource/ruby-version/index.ts index c3315f04e16dc2..f5665342b25479 100644 --- a/lib/datasource/ruby-version/index.ts +++ b/lib/datasource/ruby-version/index.ts @@ -21,7 +21,7 @@ export async function getReleases( 'all' ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/datasource/terraform-module/index.ts b/lib/datasource/terraform-module/index.ts index 62498efef9bb95..b18997eadb7e30 100644 --- a/lib/datasource/terraform-module/index.ts +++ b/lib/datasource/terraform-module/index.ts @@ -71,7 +71,7 @@ export async function getReleases({ pkgUrl ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/datasource/terraform-provider/index.ts b/lib/datasource/terraform-provider/index.ts index abe32ad04aa3a4..a97f2c333ed002 100644 --- a/lib/datasource/terraform-provider/index.ts +++ b/lib/datasource/terraform-provider/index.ts @@ -34,7 +34,7 @@ export async function getReleases({ pkgUrl ); // istanbul ignore if - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/manager/bazel/update.ts b/lib/manager/bazel/update.ts index 9d9def06e3e578..ea03cc3ff00118 100644 --- a/lib/manager/bazel/update.ts +++ b/lib/manager/bazel/update.ts @@ -51,7 +51,7 @@ async function getHashFromUrl(url: string): Promise { url ); /* istanbul ignore next line */ - if (cachedResult) { + if (cachedResult !== undefined) { return cachedResult; } try { diff --git a/lib/util/cache/global/file.spec.ts b/lib/util/cache/global/file.spec.ts index 7a774e39019ad2..e01b33536de1d9 100644 --- a/lib/util/cache/global/file.spec.ts +++ b/lib/util/cache/global/file.spec.ts @@ -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 () => { @@ -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(); }); }); diff --git a/lib/util/cache/global/file.ts b/lib/util/cache/global/file.ts index 589dd84e3a52c8..e13818c5af40be 100644 --- a/lib/util/cache/global/file.ts +++ b/lib/util/cache/global/file.ts @@ -29,7 +29,7 @@ async function get(namespace: string, key: string): Promise { } catch (err) { logger.trace({ namespace, key }, 'Cache miss'); } - return null; + return undefined; } async function set( diff --git a/lib/workers/pr/changelog/release-notes.ts b/lib/workers/pr/changelog/release-notes.ts index 2ac8bae972b617..124c3456052b5d 100644 --- a/lib/workers/pr/changelog/release-notes.ts +++ b/lib/workers/pr/changelog/release-notes.ts @@ -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, @@ -388,7 +388,7 @@ export async function addReleaseNotes( await globalCache.set( cacheNamespace, cacheKey, - releaseNotes, + releaseNotes || null, cacheMinutes ); } diff --git a/lib/workers/pr/changelog/source-github.ts b/lib/workers/pr/changelog/source-github.ts index 33e7a6c0dafc0f..24237281af30b1 100644 --- a/lib/workers/pr/changelog/source-github.ts +++ b/lib/workers/pr/changelog/source-github.ts @@ -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, diff --git a/lib/workers/pr/changelog/source-gitlab.ts b/lib/workers/pr/changelog/source-gitlab.ts index 4826fe4dd612cb..694519ca0762dd 100644 --- a/lib/workers/pr/changelog/source-gitlab.ts +++ b/lib/workers/pr/changelog/source-gitlab.ts @@ -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, diff --git a/lib/workers/repository/stats.ts b/lib/workers/repository/stats.ts index 167a8b659df7b3..dc015fc3b1aebe 100644 --- a/lib/workers/repository/stats.ts +++ b/lib/workers/repository/stats.ts @@ -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)) {