Skip to content

Commit 53f4cb6

Browse files
authored
feat(plugins/lines): add plugin_lines_delay to mitigate first query results (lowlighter#1530)
1 parent 8b410f2 commit 53f4cb6

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

source/plugins/lines/index.mjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default async function({login, data, imports, rest, q, account}, {enabled
77
return null
88

99
//Load inputs
10-
let {skipped, sections, "repositories.limit": _repositories_limit, "history.limit": _history_limit} = imports.metadata.plugins.lines.inputs({data, account, q})
10+
let {skipped, sections, "repositories.limit": _repositories_limit, "history.limit": _history_limit, delay} = imports.metadata.plugins.lines.inputs({data, account, q})
1111
skipped.push(...data.shared["repositories.skipped"])
1212

1313
//Context
@@ -25,9 +25,16 @@ export default async function({login, data, imports, rest, q, account}, {enabled
2525
//Get contributors stats from repositories
2626
console.debug(`metrics/compute/${login}/plugins > lines > querying api`)
2727
const repos = {}, weeks = {}
28-
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((
29-
{value},
30-
) => value)
28+
let response = []
29+
for (let i = 0; i < (delay ? 2 : 1); i++) {
30+
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((
31+
{value},
32+
) => value)
33+
if (delay) {
34+
console.debug(`metrics/compute/${login}/plugins > lines > waiting ${delay}s while waiting for contributor stats to be updated`)
35+
await new Promise(resolve => setTimeout(resolve, delay*1000))
36+
}
37+
}
3138

3239
//Compute changed lines
3340
console.debug(`metrics/compute/${login}/plugins > lines > computing total diff`)

source/plugins/lines/metadata.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,18 @@ inputs:
6363
Will display the last `n` years, relative to current year
6464
type: number
6565
default: 1
66+
zero: disable
67+
68+
plugin_lines_delay:
69+
description: |
70+
Delay before performing a second query
71+
72+
When non-zero, will perform a second query after specified delay (in seconds).
73+
The GitHub endpoint used may return inaccurate results on first query (these values seems to be cached on the fly),
74+
after returning correct results upon performing another query.
75+
76+
Using this option may mitigate the occurrence of weird values.
77+
type: number
78+
default: 0
79+
min: 0
6680
zero: disable

source/templates/classic/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@
891891
font-family: SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;
892892
font-weight: bold;
893893
font-size: 12px;
894-
white-space: pre;
894+
white-space: nowrap;
895895
}
896896
.added {
897897
color: rgb(63, 185, 80);

0 commit comments

Comments
 (0)