From 4d4842ff4da02fa63bf318c563589b8198f67e01 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Fri, 29 Oct 2021 23:22:51 -0400 Subject: [PATCH] fix(plugins/base): automatic halving of repositories batching when fetching them (#634) --- source/plugins/base/index.mjs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/source/plugins/base/index.mjs b/source/plugins/base/index.mjs index 8aaffd48..714c12c8 100644 --- a/source/plugins/base/index.mjs +++ b/source/plugins/base/index.mjs @@ -89,7 +89,20 @@ export default async function({login, graphql, rest, data, q, queries, imports}, data.user[type].nodes = data.user[type].nodes ?? [] do { console.debug(`metrics/compute/${login}/base > retrieving ${type} after ${cursor}`) - const {[account]:{[type]:{edges = [], nodes = []} = {}}} = await graphql(queries.base.repositories({login, account, type, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, {user:_batch, organization:Math.min(25, _batch)}[account]), ...options})) + const request = {} + try { + Object.assign(request, await graphql(queries.base.repositories({login, account, type, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, {user:_batch, organization:Math.min(25, _batch)}[account]), ...options}))) + } + catch (error) { + console.debug(`metrics/compute/${login}/base > failed to retrieve ${_batch} repositories after ${cursor}, this is probably due to an API timeout, halving batch`) + _batch = Math.floor(_batch/2) + if (_batch < 1) { + console.debug(`metrics/compute/${login}/base > failed to retrieve repositories, cannot halve batch anymore`) + throw error + } + continue + } + const {[account]:{[type]:{edges = [], nodes = []} = {}}} = request cursor = edges?.[edges?.length - 1]?.cursor data.user[type].nodes.push(...nodes) pushed = nodes.length