feat(plugins/lines): add plugin_lines_delay to mitigate first query results (#1530)

This commit is contained in:
Simon Lecoq
2023-09-12 05:07:57 +02:00
committed by GitHub
parent 8b410f24de
commit 53f4cb6920
3 changed files with 26 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled
return null return null
//Load inputs //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"]) skipped.push(...data.shared["repositories.skipped"])
//Context //Context
@@ -25,9 +25,16 @@ export default async function({login, data, imports, rest, q, account}, {enabled
//Get contributors stats from repositories //Get contributors stats from repositories
console.debug(`metrics/compute/${login}/plugins > lines > querying api`) console.debug(`metrics/compute/${login}/plugins > lines > querying api`)
const repos = {}, weeks = {} 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(( 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},
) => 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 //Compute changed lines
console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`) console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`)

View File

@@ -64,3 +64,17 @@ inputs:
type: number type: number
default: 1 default: 1
zero: disable 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

View File

@@ -891,7 +891,7 @@
font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace; font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;
font-weight: bold; font-weight: bold;
font-size: 12px; font-size: 12px;
white-space: pre; white-space: nowrap;
} }
.added { .added {
color: rgb(63, 185, 80); color: rgb(63, 185, 80);