From 3921c4007d63ab2b76d91a5a38eeb03e6692a7a8 Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@keylocation.sg> Date: Wed, 15 Nov 2017 15:39:39 +0100 Subject: [PATCH] refactor: cache pull requests (github) (#1174) --- lib/platform/github/index.js | 5 +++++ test/platform/github/index.spec.js | 2 ++ 2 files changed, 7 insertions(+) diff --git a/lib/platform/github/index.js b/lib/platform/github/index.js index 0f539aef0f..2529b4b97b 100644 --- a/lib/platform/github/index.js +++ b/lib/platform/github/index.js @@ -75,6 +75,7 @@ async function initRepo(repoName, token, endpoint) { config.repoName = repoName; config.fileList = null; config.prList = null; + config.prs = {}; const platformConfig = {}; let res; try { @@ -525,6 +526,9 @@ async function getPr(prNo) { if (!prNo) { return null; } + if (config.prs[prNo]) { + return config.prs[prNo]; + } const pr = (await get(`repos/${config.repoName}/pulls/${prNo}`)).body; if (!pr) { return null; @@ -584,6 +588,7 @@ async function getPr(prNo) { pr.isStale = true; } } + config.prs[prNo] = pr; return pr; } diff --git a/test/platform/github/index.spec.js b/test/platform/github/index.spec.js index bd051455fe..a0da3268a2 100644 --- a/test/platform/github/index.spec.js +++ b/test/platform/github/index.spec.js @@ -996,6 +996,8 @@ describe('platform/github', () => { const pr = await github.getPr(1234); expect(pr.canRebase).toBe(true); expect(pr).toMatchSnapshot(); + const cachedPr = await github.getPr(1234); + expect(cachedPr).toEqual(pr); }); }); describe('getPrFiles()', () => { -- GitLab