From bcd708fd7cf3e50433a51ae7a707dddba54f3c69 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Thu, 14 Jun 2018 09:54:00 +0200 Subject: [PATCH] feat: cache full changelog --- lib/workers/pr/changelog/index.js | 20 +++++++++---------- .../pr/__snapshots__/changelog.spec.js.snap | 2 -- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/workers/pr/changelog/index.js b/lib/workers/pr/changelog/index.js index 61a5d77d11..4517b9c95a 100644 --- a/lib/workers/pr/changelog/index.js +++ b/lib/workers/pr/changelog/index.js @@ -22,7 +22,11 @@ async function getChangeLogJSON(args) { if (!fromVersion || equals(fromVersion, toVersion)) { return null; } - + const cachedResult = await sourceCache.getChangeLogJSON(args); + if (cachedResult) { + logger.debug('Returning cached changelog'); + return cachedResult; + } let token; let endpoint; let gheBaseURL; @@ -42,16 +46,12 @@ async function getChangeLogJSON(args) { } } try { - let res = await sourceCache.getChangeLogJSON(args); - if (!res) { - res = await sourceGithub.getChangeLogJSON({ - ...args, - githubBaseURL, - }); - await sourceCache.setChangeLogJSON(args, res); - } + const res = await sourceGithub.getChangeLogJSON({ + ...args, + githubBaseURL, + }); const output = await addReleaseNotes(res); - + await sourceCache.setChangeLogJSON(args, output); return output; } catch (err) /* istanbul ignore next */ { logger.error( diff --git a/test/workers/pr/__snapshots__/changelog.spec.js.snap b/test/workers/pr/__snapshots__/changelog.spec.js.snap index 67581a19c8..fd951caaa2 100644 --- a/test/workers/pr/__snapshots__/changelog.spec.js.snap +++ b/test/workers/pr/__snapshots__/changelog.spec.js.snap @@ -163,14 +163,12 @@ Object { Object { "changes": Array [], "compare": Object {}, - "releaseNotes": undefined, "version": "2.5.2", }, Object { "changes": Array [], "compare": Object {}, "date": "2017-12-24T03:20:46.238Z", - "releaseNotes": undefined, "version": "2.4.2", }, Object { -- GitLab