diff --git a/lib/platform/github/gh-got-wrapper.js b/lib/platform/github/gh-got-wrapper.js index c5789abbb39f11707d1e8c9a5e00070f8da7fc83..3a2e61827b721ebd31383796c111d29b628fffd5 100644 --- a/lib/platform/github/gh-got-wrapper.js +++ b/lib/platform/github/gh-got-wrapper.js @@ -42,6 +42,20 @@ async function get(path, options, retries = 5) { const pageLimit = opts.pageLimit || 10; const linkHeader = parseLinkHeader(res.headers.link); if (linkHeader && linkHeader.next && linkHeader.last) { + const { etag } = res.headers; + const cacheNamespace = 'github-pagination'; + // istanbul ignore next + try { + const cacheResult = await renovateCache.get(cacheNamespace, path); + if (cacheResult.etag === etag) { + logger.trace({ path }, 'Returning cached paginated result'); + res.body = cacheResult.body; + return res; + } + logger.trace({ path }, 'Outdated pagination cache'); + } catch (err) { + logger.trace({ path }, 'Paginated cache miss'); + } let lastPage = +linkHeader.last.page; if (!process.env.RENOVATE_PAGINATE_ALL) { lastPage = Math.min(pageLimit, lastPage); @@ -61,6 +75,13 @@ async function get(path, options, retries = 5) { res.body = res.body.concat( ...pages.filter(Boolean).map(page => page.body) ); + const cacheMinutes = 60 * 24; + await renovateCache.set( + cacheNamespace, + path, + { etag, body: res.body }, + cacheMinutes + ); } } if (