Skip to content

Commit

Permalink
Remove await from inside of loops
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jul 26, 2023
1 parent c36ed8e commit be3f1b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
17 changes: 7 additions & 10 deletions extension/src/experiments/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
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.collectGitLogAndOrder(branch, rowOrder, availableNbCommits, args)
)
}
const gitBranchLogs = await Promise.all(promises)
const gitLog = gitBranchLogs.join(COMMITS_SEPARATOR)

const expShow = await this.internalCommands.executeCommand<ExpShowOutput>(
AvailableCommands.EXP_SHOW,
Expand All @@ -82,7 +80,6 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
}

private async collectGitLogAndOrder(
gitLog: string,
branch: string,
rowOrder: { branch: string; sha: string }[],
availableNbCommits: { [branch: string]: number },
Expand All @@ -103,7 +100,7 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
branch
)
])
gitLog = [gitLog, branchGitLog].join(COMMITS_SEPARATOR)

availableNbCommits[branch] = totalCommits

for (const commit of branchGitLog.split(COMMITS_SEPARATOR)) {
Expand All @@ -114,7 +111,7 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
}
args.push(ExperimentFlag.REV, sha)
}
return gitLog
return branchGitLog
}

private async updateBranches() {
Expand Down
8 changes: 7 additions & 1 deletion extension/src/repository/model/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit be3f1b1

Please sign in to comment.