Skip to content
Snippets Groups Projects
Commit 4d48ba13 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor: cache changelog per-release

Closes #2473
parent 737485f6
No related branches found
No related tags found
No related merge requests found
...@@ -6,13 +6,6 @@ module.exports = { ...@@ -6,13 +6,6 @@ module.exports = {
getChangeLogJSON, getChangeLogJSON,
}; };
const cacheNamespace = 'changelog';
function getCacheKey({ repositoryUrl, releases }) {
return `${repositoryUrl}-${
releases ? releases.map(release => release.version).join('-') : ''
}`;
}
async function getChangeLogJSON(args) { async function getChangeLogJSON(args) {
const { repositoryUrl, versionScheme, fromVersion, toVersion } = args; const { repositoryUrl, versionScheme, fromVersion, toVersion } = args;
if (!repositoryUrl) { if (!repositoryUrl) {
...@@ -25,23 +18,8 @@ async function getChangeLogJSON(args) { ...@@ -25,23 +18,8 @@ async function getChangeLogJSON(args) {
if (!fromVersion || equals(fromVersion, toVersion)) { if (!fromVersion || equals(fromVersion, toVersion)) {
return null; return null;
} }
const cachedResult = await renovateCache.get(
cacheNamespace,
getCacheKey(args)
);
if (cachedResult) {
return cachedResult;
}
try { try {
const res = await sourceGithub.getChangeLogJSON({ ...args }); const res = await sourceGithub.getChangeLogJSON({ ...args });
const cacheMinutes = 60;
await renovateCache.set(
cacheNamespace,
getCacheKey(args),
res,
cacheMinutes
);
return res; return res;
} catch (err) /* istanbul ignore next */ { } catch (err) /* istanbul ignore next */ {
logger.error( logger.error(
......
...@@ -182,8 +182,16 @@ async function addReleaseNotes(input) { ...@@ -182,8 +182,16 @@ async function addReleaseNotes(input) {
} }
const output = { ...input, versions: [] }; const output = { ...input, versions: [] };
const repository = input.project.github.replace(/\.git$/, ''); const repository = input.project.github.replace(/\.git$/, '');
const cacheNamespace = 'changelog-github-notes';
function getCacheKey(version) {
return `${repository}:${version}`;
}
for (const v of input.versions) { for (const v of input.versions) {
let releaseNotes = await getReleaseNotesMd( let releaseNotes;
const cacheKey = getCacheKey(v.version);
releaseNotes = await renovateCache.get(cacheNamespace, cacheKey);
if (!releaseNotes) {
releaseNotes = await getReleaseNotesMd(
repository, repository,
v.version, v.version,
input.project.githubBaseURL input.project.githubBaseURL
...@@ -200,6 +208,14 @@ async function addReleaseNotes(input) { ...@@ -200,6 +208,14 @@ async function addReleaseNotes(input) {
if (!releaseNotes && v.compare.url) { if (!releaseNotes && v.compare.url) {
releaseNotes = { url: v.compare.url }; releaseNotes = { url: v.compare.url };
} }
const cacheMinutes = 30;
await renovateCache.set(
cacheNamespace,
cacheKey,
releaseNotes,
cacheMinutes
);
}
output.versions.push({ output.versions.push({
...v, ...v,
releaseNotes, releaseNotes,
......
...@@ -108,6 +108,11 @@ async function getChangeLogJSON({ ...@@ -108,6 +108,11 @@ async function getChangeLogJSON({
return getDateRef(config.endpoint, repository, release.releaseTimestamp); return getDateRef(config.endpoint, repository, release.releaseTimestamp);
} }
const cacheNamespace = 'changelog-github-release';
function getCacheKey(version) {
return `${repository}:${version}`;
}
const changelogReleases = []; const changelogReleases = [];
// compare versions // compare versions
const include = version => const include = version =>
...@@ -116,7 +121,12 @@ async function getChangeLogJSON({ ...@@ -116,7 +121,12 @@ async function getChangeLogJSON({
const prev = validReleases[i - 1]; const prev = validReleases[i - 1];
const next = validReleases[i]; const next = validReleases[i];
if (include(next.version)) { if (include(next.version)) {
const release = { let release = await renovateCache.get(
cacheNamespace,
getCacheKey(next.version)
);
if (!release) {
release = {
version: next.version, version: next.version,
date: next.releaseTimestamp, date: next.releaseTimestamp,
// put empty changes so that existing templates won't break // put empty changes so that existing templates won't break
...@@ -128,6 +138,14 @@ async function getChangeLogJSON({ ...@@ -128,6 +138,14 @@ async function getChangeLogJSON({
if (prevHead && nextHead) { if (prevHead && nextHead) {
release.compare.url = `${githubBaseURL}${repository}/compare/${prevHead}...${nextHead}`; release.compare.url = `${githubBaseURL}${repository}/compare/${prevHead}...${nextHead}`;
} }
const cacheMinutes = 30;
await renovateCache.set(
cacheNamespace,
getCacheKey(next.version),
release,
cacheMinutes
);
}
changelogReleases.unshift(release); changelogReleases.unshift(release);
} }
} }
......
...@@ -163,12 +163,14 @@ Object { ...@@ -163,12 +163,14 @@ Object {
Object { Object {
"changes": Array [], "changes": Array [],
"compare": Object {}, "compare": Object {},
"releaseNotes": undefined,
"version": "2.5.2", "version": "2.5.2",
}, },
Object { Object {
"changes": Array [], "changes": Array [],
"compare": Object {}, "compare": Object {},
"date": "2017-12-24T03:20:46.238Z", "date": "2017-12-24T03:20:46.238Z",
"releaseNotes": undefined,
"version": "2.4.2", "version": "2.4.2",
}, },
Object { Object {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment