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
...@@ -51,7 +51,7 @@ async function getHashFromUrl(url: string): Promise<string | null> { ...@@ -51,7 +51,7 @@ async function getHashFromUrl(url: string): Promise<string | null> {
url url
); );
/* istanbul ignore next line */ /* istanbul ignore next line */
if (cachedResult) { if (cachedResult !== undefined) {
return cachedResult; return cachedResult;
} }
try { try {
......
...@@ -6,8 +6,10 @@ describe('lib/util/cache/global/file', () => { ...@@ -6,8 +6,10 @@ describe('lib/util/cache/global/file', () => {
init(os.tmpdir()); init(os.tmpdir());
}); });
it('gets null', async () => { it('returns undefined if no match', async () => {
expect(await global.renovateCache.get('test', 'missing-key')).toBeNull(); expect(
await global.renovateCache.get('test', 'missing-key')
).toBeUndefined();
}); });
it('sets and gets', async () => { it('sets and gets', async () => {
...@@ -17,6 +19,6 @@ describe('lib/util/cache/global/file', () => { ...@@ -17,6 +19,6 @@ describe('lib/util/cache/global/file', () => {
it('expires', async () => { it('expires', async () => {
await global.renovateCache.set('test', 'key', 1234, -5); await global.renovateCache.set('test', 'key', 1234, -5);
expect(await global.renovateCache.get('test', 'key')).toBeNull(); expect(await global.renovateCache.get('test', 'key')).toBeUndefined();
}); });
}); });
...@@ -29,7 +29,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> { ...@@ -29,7 +29,7 @@ async function get<T = never>(namespace: string, key: string): Promise<T> {
} catch (err) { } catch (err) {
logger.trace({ namespace, key }, 'Cache miss'); logger.trace({ namespace, key }, 'Cache miss');
} }
return null; return undefined;
} }
async function set( async function set(
......
...@@ -355,7 +355,7 @@ export async function addReleaseNotes( ...@@ -355,7 +355,7 @@ export async function addReleaseNotes(
let releaseNotes: ChangeLogNotes; let releaseNotes: ChangeLogNotes;
const cacheKey = getCacheKey(v.version); const cacheKey = getCacheKey(v.version);
releaseNotes = await globalCache.get(cacheNamespace, cacheKey); releaseNotes = await globalCache.get(cacheNamespace, cacheKey);
if (!releaseNotes) { if (releaseNotes === undefined) {
if (input.project.github != null) { if (input.project.github != null) {
releaseNotes = await getReleaseNotesMd( releaseNotes = await getReleaseNotesMd(
repository, repository,
...@@ -388,7 +388,7 @@ export async function addReleaseNotes( ...@@ -388,7 +388,7 @@ export async function addReleaseNotes(
await globalCache.set( await globalCache.set(
cacheNamespace, cacheNamespace,
cacheKey, cacheKey,
releaseNotes, releaseNotes || null,
cacheMinutes cacheMinutes
); );
} }
......
...@@ -155,7 +155,7 @@ export async function getChangeLogJSON({ ...@@ -155,7 +155,7 @@ export async function getChangeLogJSON({
getCacheKey(prev.version, next.version) getCacheKey(prev.version, next.version)
); );
// istanbul ignore else // istanbul ignore else
if (!release) { if (release === undefined) {
release = { release = {
version: next.version, version: next.version,
date: next.releaseTimestamp, date: next.releaseTimestamp,
......
...@@ -135,7 +135,7 @@ export async function getChangeLogJSON({ ...@@ -135,7 +135,7 @@ export async function getChangeLogJSON({
cacheNamespace, cacheNamespace,
getCacheKey(prev.version, next.version) getCacheKey(prev.version, next.version)
); );
if (!release) { if (release === undefined) {
release = { release = {
version: next.version, version: next.version,
date: next.releaseTimestamp, date: next.releaseTimestamp,
......
...@@ -26,7 +26,7 @@ export function printRequestStats(): void { ...@@ -26,7 +26,7 @@ export function printRequestStats(): void {
requestHosts[hostname] = requestHosts[hostname] || []; requestHosts[hostname] = requestHosts[hostname] || [];
requestHosts[hostname].push(request.duration); requestHosts[hostname].push(request.duration);
} }
logger.trace({ allRequests, requestHosts }, 'full stats'); logger.debug({ allRequests, requestHosts }, 'full stats');
const hostStats: string[] = []; const hostStats: string[] = [];
let totalRequests = 0; let totalRequests = 0;
for (const [hostname, requests] of Object.entries(requestHosts)) { for (const [hostname, requests] of Object.entries(requestHosts)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment