From 11cdce50f799fdfa148ed351bca0ec8558beadf5 Mon Sep 17 00:00:00 2001 From: Matt Seddon Date: Wed, 26 Jul 2023 17:55:15 +1000 Subject: [PATCH] Remove await from inside of loops --- extension/src/experiments/data/index.ts | 53 +++++++++++++---------- extension/src/repository/model/collect.ts | 8 +++- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/extension/src/experiments/data/index.ts b/extension/src/experiments/data/index.ts index fd4f422164..16345d90f5 100644 --- a/extension/src/experiments/data/index.ts +++ b/extension/src/experiments/data/index.ts @@ -56,21 +56,16 @@ export class ExperimentsData extends BaseData { private async updateExpShow() { await this.updateBranches() const branches = this.experiments.getBranchesToShow() - let gitLog = '' - const rowOrder: { branch: string; sha: string }[] = [] const availableNbCommits: { [branch: string]: number } = {} - const args: Args = [] + const promises = [] for (const branch of branches) { - gitLog = await this.collectGitLogAndOrder( - gitLog, - branch, - rowOrder, - availableNbCommits, - args - ) + promises.push(this.collectGitLogByBranch(branch, availableNbCommits)) } + const branchLogs = await Promise.all(promises) + const { args, gitLog, rowOrder } = this.collectGitLogAndOrder(branchLogs) + const expShow = await this.internalCommands.executeCommand( AvailableCommands.EXP_SHOW, this.dvcRoot, @@ -81,16 +76,13 @@ export class ExperimentsData extends BaseData { return { availableNbCommits, expShow, gitLog, rowOrder } } - private async collectGitLogAndOrder( - gitLog: string, + private async collectGitLogByBranch( branch: string, - rowOrder: { branch: string; sha: string }[], - availableNbCommits: { [branch: string]: number }, - args: Args + availableNbCommits: { [branch: string]: number } ) { const nbOfCommitsToShow = this.experiments.getNbOfCommitsToShow(branch) - const [branchGitLog, totalCommits] = await Promise.all([ + const [branchLog, totalCommits] = await Promise.all([ this.internalCommands.executeCommand( AvailableCommands.GIT_GET_COMMIT_MESSAGES, this.dvcRoot, @@ -103,18 +95,31 @@ export class ExperimentsData extends BaseData { branch ) ]) - gitLog = [gitLog, branchGitLog].join(COMMITS_SEPARATOR) + availableNbCommits[branch] = totalCommits - for (const commit of branchGitLog.split(COMMITS_SEPARATOR)) { - const [sha] = commit.split('\n') - rowOrder.push({ branch, sha }) - if (args.includes(sha)) { - continue + return { branch, branchLog } + } + + private collectGitLogAndOrder( + branchLogs: { branch: string; branchLog: string }[] + ) { + const rowOrder: { branch: string; sha: string }[] = [] + const args: Args = [] + const gitLog: string[] = [] + + for (const { branch, branchLog } of branchLogs) { + gitLog.push(branchLog) + for (const commit of branchLog.split(COMMITS_SEPARATOR)) { + const [sha] = commit.split('\n') + rowOrder.push({ branch, sha }) + if (args.includes(sha)) { + continue + } + args.push(ExperimentFlag.REV, sha) } - args.push(ExperimentFlag.REV, sha) } - return gitLog + return { args, gitLog: gitLog.join(COMMITS_SEPARATOR), rowOrder } } private async updateBranches() { diff --git a/extension/src/repository/model/collect.ts b/extension/src/repository/model/collect.ts index 6b14c7b567..8116db6171 100644 --- a/extension/src/repository/model/collect.ts +++ b/extension/src/repository/model/collect.ts @@ -335,9 +335,15 @@ export const collectTrackedPaths = async ( return acc } const children = await getChildren(resourceUri.fsPath) + const promises = [] for (const child of children) { - acc.push(...(await collectTrackedPaths(child, getChildren))) + promises.push(collectTrackedPaths(child, getChildren)) } + const results = await Promise.all(promises) + for (const result of results) { + acc.push(...result) + } + return acc }