From 0d56e018a9a2737eb1a440f807beda191daa76e0 Mon Sep 17 00:00:00 2001 From: Raicuparta Date: Sat, 1 Oct 2022 00:41:35 +0200 Subject: [PATCH] fix time measurement --- fetch-mods/get-install-counts.ts | 2 +- fetch-mods/index.ts | 51 ++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/fetch-mods/get-install-counts.ts b/fetch-mods/get-install-counts.ts index 923008718d..54780a6d66 100644 --- a/fetch-mods/get-install-counts.ts +++ b/fetch-mods/get-install-counts.ts @@ -12,7 +12,7 @@ export async function getInstallCounts( ).toString(); const analyticsDataClient = new BetaAnalyticsDataClient({ - credentials: JSON.parse(base64GoogleServiceAccountCredentials), + credentials: JSON.parse(googleServiceAccountCredentials), projectId: "outer-wilds-mods", }); diff --git a/fetch-mods/index.ts b/fetch-mods/index.ts index 5123a98f47..c22f25b5a8 100644 --- a/fetch-mods/index.ts +++ b/fetch-mods/index.ts @@ -37,30 +37,40 @@ export const getModPathName = (modName: string) => modName.replace(/\W/g, "").toLowerCase(); const getSettledResult = ( - results: PromiseSettledResult, - name: string, - initialTime: number + results: PromiseSettledResult ): TResult | undefined => { if (results.status == "rejected") return undefined; - console.log( - `Finished getting ${name} in ${performance.now() - initialTime} ms` - ); - return results.value; }; +const measureTime = (promise: Promise, name: string) => { + const initialTime = performance.now(); + + promise.finally(() => { + `Method "${name}" took ${ + performance.now() - initialTime + } seconds to finish.`; + }); + + return promise; +}; + async function getAsyncStuff() { const promises = [ - fetchModManager(), - fetchMods(core.getInput(Input.mods)), - getViewCounts(core.getInput(Input.googleServiceAccount)), - getInstallCounts(core.getInput(Input.googleServiceAccount)), - getPreviousDatabase(), + measureTime(fetchModManager(), "fetchModManager"), + measureTime(fetchMods(core.getInput(Input.mods)), "fetchMods"), + measureTime( + getViewCounts(core.getInput(Input.googleServiceAccount)), + "getViewCounts" + ), + measureTime( + getInstallCounts(core.getInput(Input.googleServiceAccount)), + "getInstallCounts" + ), + measureTime(getPreviousDatabase(), "getPreviousDatabase"), ] as const; - const initialTime = performance.now(); - const [ modManager, nextDatabase, @@ -70,14 +80,11 @@ async function getAsyncStuff() { ] = await Promise.allSettled(promises); return { - modManager: getSettledResult(modManager, "modManager", initialTime), - nextDatabase: - getSettledResult(nextDatabase, "nextDatabase", initialTime) ?? [], - viewCounts: getSettledResult(viewCounts, "viewCounts", initialTime) ?? {}, - installCounts: - getSettledResult(installCounts, "installCounts", initialTime) ?? {}, - previousDatabase: - getSettledResult(previousDatabase, "previousDatabase", initialTime) ?? [], + modManager: getSettledResult(modManager), + nextDatabase: getSettledResult(nextDatabase) ?? [], + viewCounts: getSettledResult(viewCounts) ?? {}, + installCounts: getSettledResult(installCounts) ?? {}, + previousDatabase: getSettledResult(previousDatabase) ?? [], }; }