Skip to content

Commit 9b34b38

Browse files
authored
Remove await from inside of loops (#4354)
1 parent 1baf38e commit 9b34b38

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

extension/src/experiments/data/index.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,16 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
5656
private async updateExpShow() {
5757
await this.updateBranches()
5858
const branches = this.experiments.getBranchesToShow()
59-
let gitLog = ''
60-
const rowOrder: { branch: string; sha: string }[] = []
6159
const availableNbCommits: { [branch: string]: number } = {}
62-
const args: Args = []
6360

61+
const promises = []
6462
for (const branch of branches) {
65-
gitLog = await this.collectGitLogAndOrder(
66-
gitLog,
67-
branch,
68-
rowOrder,
69-
availableNbCommits,
70-
args
71-
)
63+
promises.push(this.collectGitLogByBranch(branch, availableNbCommits))
7264
}
7365

66+
const branchLogs = await Promise.all(promises)
67+
const { args, gitLog, rowOrder } = this.collectGitLogAndOrder(branchLogs)
68+
7469
const expShow = await this.internalCommands.executeCommand<ExpShowOutput>(
7570
AvailableCommands.EXP_SHOW,
7671
this.dvcRoot,
@@ -81,16 +76,13 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
8176
return { availableNbCommits, expShow, gitLog, rowOrder }
8277
}
8378

84-
private async collectGitLogAndOrder(
85-
gitLog: string,
79+
private async collectGitLogByBranch(
8680
branch: string,
87-
rowOrder: { branch: string; sha: string }[],
88-
availableNbCommits: { [branch: string]: number },
89-
args: Args
81+
availableNbCommits: { [branch: string]: number }
9082
) {
9183
const nbOfCommitsToShow = this.experiments.getNbOfCommitsToShow(branch)
9284

93-
const [branchGitLog, totalCommits] = await Promise.all([
85+
const [branchLog, totalCommits] = await Promise.all([
9486
this.internalCommands.executeCommand(
9587
AvailableCommands.GIT_GET_COMMIT_MESSAGES,
9688
this.dvcRoot,
@@ -103,18 +95,31 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
10395
branch
10496
)
10597
])
106-
gitLog = [gitLog, branchGitLog].join(COMMITS_SEPARATOR)
98+
10799
availableNbCommits[branch] = totalCommits
108100

109-
for (const commit of branchGitLog.split(COMMITS_SEPARATOR)) {
110-
const [sha] = commit.split('\n')
111-
rowOrder.push({ branch, sha })
112-
if (args.includes(sha)) {
113-
continue
101+
return { branch, branchLog }
102+
}
103+
104+
private collectGitLogAndOrder(
105+
branchLogs: { branch: string; branchLog: string }[]
106+
) {
107+
const rowOrder: { branch: string; sha: string }[] = []
108+
const args: Args = []
109+
const gitLog: string[] = []
110+
111+
for (const { branch, branchLog } of branchLogs) {
112+
gitLog.push(branchLog)
113+
for (const commit of branchLog.split(COMMITS_SEPARATOR)) {
114+
const [sha] = commit.split('\n')
115+
rowOrder.push({ branch, sha })
116+
if (args.includes(sha)) {
117+
continue
118+
}
119+
args.push(ExperimentFlag.REV, sha)
114120
}
115-
args.push(ExperimentFlag.REV, sha)
116121
}
117-
return gitLog
122+
return { args, gitLog: gitLog.join(COMMITS_SEPARATOR), rowOrder }
118123
}
119124

120125
private async updateBranches() {

extension/src/repository/model/collect.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,15 @@ export const collectTrackedPaths = async (
335335
return acc
336336
}
337337
const children = await getChildren(resourceUri.fsPath)
338+
const promises = []
338339
for (const child of children) {
339-
acc.push(...(await collectTrackedPaths(child, getChildren)))
340+
promises.push(collectTrackedPaths(child, getChildren))
340341
}
342+
const results = await Promise.all(promises)
343+
for (const result of results) {
344+
acc.push(...result)
345+
}
346+
341347
return acc
342348
}
343349

0 commit comments

Comments
 (0)