Skip to content

Commit

Permalink
Remove await from inside of loops (#4354)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Jul 26, 2023
1 parent 1baf38e commit 9b34b38
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
53 changes: 29 additions & 24 deletions extension/src/experiments/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,16 @@ 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.collectGitLogByBranch(branch, availableNbCommits))
}

const branchLogs = await Promise.all(promises)
const { args, gitLog, rowOrder } = this.collectGitLogAndOrder(branchLogs)

const expShow = await this.internalCommands.executeCommand<ExpShowOutput>(
AvailableCommands.EXP_SHOW,
this.dvcRoot,
Expand All @@ -81,16 +76,13 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
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,
Expand All @@ -103,18 +95,31 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
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() {
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 9b34b38

Please sign in to comment.