From f5b879434c5afa0e9b69d1df6d246af3f6c34dec Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 9 Jun 2021 13:12:25 +0200 Subject: [PATCH] Fix race issue between habits and languages plugin --- source/plugins/habits/index.mjs | 2 +- source/plugins/languages/analyzers.mjs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/plugins/habits/index.mjs b/source/plugins/habits/index.mjs index c904c723..62b50f8f 100644 --- a/source/plugins/habits/index.mjs +++ b/source/plugins/habits/index.mjs @@ -103,7 +103,7 @@ export default async function({login, data, rest, imports, q, account}, {enabled if ((patches.length) && (await imports.which("github-linguist"))) { //Call language analyzer (note: using content from other plugin is usually disallowed, this is mostly for legacy purposes) habits.linguist.available = true - const {total, stats} = await recent_analyzer({login, data, imports, rest, account}, {days, load:from || 1000}) + const {total, stats} = await recent_analyzer({login, data, imports, rest, account}, {days, load:from || 1000, tempdir:"habits"}) habits.linguist.languages = Object.fromEntries(Object.entries(stats).map(([language, value]) => [language, value/total])) habits.linguist.ordered = Object.entries(habits.linguist.languages).sort(([_an, a], [_bn, b]) => b - a) } diff --git a/source/plugins/languages/analyzers.mjs b/source/plugins/languages/analyzers.mjs index 425f55b9..3dd2b2f5 100644 --- a/source/plugins/languages/analyzers.mjs +++ b/source/plugins/languages/analyzers.mjs @@ -45,7 +45,7 @@ export async function indepth({login, data, imports, repositories}, {skipped}) { } /**Recent languages activity */ -export async function recent({login, data, imports, rest, account}, {skipped = [], days = 0, load = 0}) { +export async function recent({login, data, imports, rest, account}, {skipped = [], days = 0, load = 0, tempdir = "recent"}) { //Check prerequisites if (!await imports.which("github-linguist")) throw new Error("Feature requires github-linguist") @@ -89,7 +89,7 @@ export async function recent({login, data, imports, rest, account}, {skipped = [ .map(({name, directory, patch, repo}) => ({name, directory:`${repo.replace(/[/]/g, "@")}/${directory}`, patch:patch.split("\n").filter(line => /^[+]/.test(line)).map(line => line.substring(1)).join("\n")})) //Temporary directory - const path = imports.paths.join(imports.os.tmpdir(), `${data.user.databaseId}`) + const path = imports.paths.join(imports.os.tmpdir(), `${data.user.databaseId}-${tempdir}`) console.debug(`metrics/compute/${login}/plugins > languages > creating temp dir ${path} with ${patches.length} files`) results.files = patches.length