feat(plugins/lines): add plugin_lines_delay to mitigate first query results (#1530)
This commit is contained in:
@@ -7,7 +7,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {skipped, sections, "repositories.limit": _repositories_limit, "history.limit": _history_limit} = imports.metadata.plugins.lines.inputs({data, account, q})
|
||||
let {skipped, sections, "repositories.limit": _repositories_limit, "history.limit": _history_limit, delay} = imports.metadata.plugins.lines.inputs({data, account, q})
|
||||
skipped.push(...data.shared["repositories.skipped"])
|
||||
|
||||
//Context
|
||||
@@ -25,9 +25,16 @@ export default async function({login, data, imports, rest, q, account}, {enabled
|
||||
//Get contributors stats from repositories
|
||||
console.debug(`metrics/compute/${login}/plugins > lines > querying api`)
|
||||
const repos = {}, weeks = {}
|
||||
const response = [...await Promise.allSettled(repositories.map(async ({repo, owner}) => imports.filters.repo(`${owner}/${repo}`, skipped) ? {handle: `${owner}/${repo}`, stats: (await rest.repos.getContributorsStats({owner, repo})).data} : {}))].filter(({status}) => status === "fulfilled").map((
|
||||
{value},
|
||||
) => value)
|
||||
let response = []
|
||||
for (let i = 0; i < (delay ? 2 : 1); i++) {
|
||||
response = [...await Promise.allSettled(repositories.map(async ({repo, owner}) => imports.filters.repo(`${owner}/${repo}`, skipped) ? {handle: `${owner}/${repo}`, stats: (await rest.repos.getContributorsStats({owner, repo})).data} : {}))].filter(({status}) => status === "fulfilled").map((
|
||||
{value},
|
||||
) => value)
|
||||
if (delay) {
|
||||
console.debug(`metrics/compute/${login}/plugins > lines > waiting ${delay}s while waiting for contributor stats to be updated`)
|
||||
await new Promise(resolve => setTimeout(resolve, delay*1000))
|
||||
}
|
||||
}
|
||||
|
||||
//Compute changed lines
|
||||
console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`)
|
||||
|
||||
@@ -63,4 +63,18 @@ inputs:
|
||||
Will display the last `n` years, relative to current year
|
||||
type: number
|
||||
default: 1
|
||||
zero: disable
|
||||
|
||||
plugin_lines_delay:
|
||||
description: |
|
||||
Delay before performing a second query
|
||||
|
||||
When non-zero, will perform a second query after specified delay (in seconds).
|
||||
The GitHub endpoint used may return inaccurate results on first query (these values seems to be cached on the fly),
|
||||
after returning correct results upon performing another query.
|
||||
|
||||
Using this option may mitigate the occurrence of weird values.
|
||||
type: number
|
||||
default: 0
|
||||
min: 0
|
||||
zero: disable
|
||||
Reference in New Issue
Block a user