Skip to content
Snippets Groups Projects
Unverified Commit 0345b40a authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

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

null = this lookup returned nothing last time
undefined = no cached result found
parent 8ac8f42a
Branches
No related tags found
No related merge requests found
Showing
with 25 additions and 28 deletions
...@@ -60,7 +60,7 @@ export async function cacheAble<TArg, TResult = unknown>({ ...@@ -60,7 +60,7 @@ export async function cacheAble<TArg, TResult = unknown>({
const cacheKey = JSON.stringify(lookup); const cacheKey = JSON.stringify(lookup);
const cachedResult = await globalCache.get<TResult>(cacheNamespace, cacheKey); const cachedResult = await globalCache.get<TResult>(cacheNamespace, cacheKey);
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
logger.trace({ id, lookup }, 'datasource cachedResult'); logger.trace({ id, lookup }, 'datasource cachedResult');
return cachedResult; return cachedResult;
} }
......
...@@ -22,7 +22,7 @@ export async function getReleases({ ...@@ -22,7 +22,7 @@ export async function getReleases({
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -341,7 +341,7 @@ export async function getDigest( ...@@ -341,7 +341,7 @@ export async function getDigest(
const cacheKey = `${registry}:${repository}:${newTag}`; const cacheKey = `${registry}:${repository}:${newTag}`;
const cachedResult = await globalCache.get(cacheNamespace, cacheKey); const cachedResult = await globalCache.get(cacheNamespace, cacheKey);
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
const manifestResponse = await getManifestResponse( const manifestResponse = await getManifestResponse(
...@@ -386,7 +386,7 @@ async function getTags( ...@@ -386,7 +386,7 @@ async function getTags(
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
// AWS ECR limits the maximum number of results to 1000 // AWS ECR limits the maximum number of results to 1000
...@@ -486,7 +486,7 @@ async function getLabels( ...@@ -486,7 +486,7 @@ async function getLabels(
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
...@@ -22,7 +22,7 @@ export async function getReleases({ ...@@ -22,7 +22,7 @@ export async function getReleases({
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -29,7 +29,7 @@ export async function getRawRefs({ ...@@ -29,7 +29,7 @@ export async function getRawRefs({
lookupName lookupName
); );
/* istanbul ignore next line */ /* istanbul ignore next line */
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -18,7 +18,7 @@ export async function getReleases({ ...@@ -18,7 +18,7 @@ export async function getReleases({
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -33,7 +33,7 @@ export async function getReleases({ ...@@ -33,7 +33,7 @@ export async function getReleases({
repo repo
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
...@@ -29,7 +29,7 @@ async function getTagCommit( ...@@ -29,7 +29,7 @@ async function getTagCommit(
getCacheKey(githubRepo, `tag-${tag}`) getCacheKey(githubRepo, `tag-${tag}`)
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
let digest: string; let digest: string;
...@@ -81,7 +81,7 @@ export async function getDigest( ...@@ -81,7 +81,7 @@ export async function getDigest(
getCacheKey(githubRepo, 'commit') getCacheKey(githubRepo, 'commit')
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
let digest: string; let digest: string;
...@@ -95,9 +95,6 @@ export async function getDigest( ...@@ -95,9 +95,6 @@ export async function getDigest(
'Error getting latest commit from GitHub repo' 'Error getting latest commit from GitHub repo'
); );
} }
if (!digest) {
return null;
}
const cacheMinutes = 10; const cacheMinutes = 10;
await globalCache.set( await globalCache.set(
cacheNamespace, cacheNamespace,
...@@ -105,7 +102,7 @@ export async function getDigest( ...@@ -105,7 +102,7 @@ export async function getDigest(
digest, digest,
cacheMinutes cacheMinutes
); );
return digest; return digest || null;
} }
/** /**
...@@ -127,7 +124,7 @@ export async function getReleases({ ...@@ -127,7 +124,7 @@ export async function getReleases({
getCacheKey(repo, 'tags') getCacheKey(repo, 'tags')
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
...@@ -35,7 +35,7 @@ export async function getReleases({ ...@@ -35,7 +35,7 @@ export async function getReleases({
getCacheKey(depHost, repo) getCacheKey(depHost, repo)
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -21,7 +21,7 @@ export async function getRepositoryData( ...@@ -21,7 +21,7 @@ export async function getRepositoryData(
const cacheKey = repository; const cacheKey = repository;
const cachedIndex = await globalCache.get(cacheNamespace, cacheKey); const cachedIndex = await globalCache.get(cacheNamespace, cacheKey);
// istanbul ignore if // istanbul ignore if
if (cachedIndex) { if (cachedIndex !== undefined) {
return cachedIndex; return cachedIndex;
} }
let res: any; let res: any;
......
...@@ -162,7 +162,7 @@ async function getVersionsFromMetadata( ...@@ -162,7 +162,7 @@ async function getVersionsFromMetadata(
cacheKey cacheKey
); );
/* istanbul ignore if */ /* istanbul ignore if */
if (cachedVersions) { if (cachedVersions !== undefined) {
return cachedVersions; return cachedVersions;
} }
......
...@@ -75,7 +75,7 @@ export async function getDependency( ...@@ -75,7 +75,7 @@ export async function getDependency(
pkgUrl pkgUrl
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
const headers: OutgoingHttpHeaders = {}; const headers: OutgoingHttpHeaders = {};
......
...@@ -24,7 +24,7 @@ export async function getQueryUrl(url: string): Promise<string | null> { ...@@ -24,7 +24,7 @@ export async function getQueryUrl(url: string): Promise<string | null> {
const cachedResult = await globalCache.get<string>(cacheNamespace, cacheKey); const cachedResult = await globalCache.get<string>(cacheNamespace, cacheKey);
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -31,7 +31,7 @@ export async function getReleases({ ...@@ -31,7 +31,7 @@ export async function getReleases({
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
const url = 'https://circleci.com/graphql-unstable'; const url = 'https://circleci.com/graphql-unstable';
......
...@@ -236,7 +236,7 @@ async function packagistOrgLookup(name: string): Promise<ReleaseResult> { ...@@ -236,7 +236,7 @@ async function packagistOrgLookup(name: string): Promise<ReleaseResult> {
name name
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
let dep: ReleaseResult = null; let dep: ReleaseResult = null;
......
...@@ -158,7 +158,7 @@ export async function getReleases({ ...@@ -158,7 +158,7 @@ export async function getReleases({
podName podName
); );
/* istanbul ignore next line */ /* istanbul ignore next line */
if (cachedResult) { if (cachedResult !== undefined) {
logger.debug(`CocoaPods: Return cached result for ${podName}`); logger.debug(`CocoaPods: Return cached result for ${podName}`);
return cachedResult; return cachedResult;
} }
......
...@@ -89,7 +89,7 @@ async function getCachedPackage( ...@@ -89,7 +89,7 @@ async function getCachedPackage(
cacheKey cacheKey
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
......
...@@ -21,7 +21,7 @@ export async function getReleases( ...@@ -21,7 +21,7 @@ export async function getReleases(
'all' 'all'
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
...@@ -71,7 +71,7 @@ export async function getReleases({ ...@@ -71,7 +71,7 @@ export async function getReleases({
pkgUrl pkgUrl
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
...@@ -34,7 +34,7 @@ export async function getReleases({ ...@@ -34,7 +34,7 @@ export async function getReleases({
pkgUrl pkgUrl
); );
// istanbul ignore if // istanbul ignore if
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment