Skip to content

Commit

Permalink
Revert "Use expShow once with multiple revisions"
Browse files Browse the repository at this point in the history
This reverts commit ac55156.
  • Loading branch information
Stephanie Roy committed May 24, 2023
1 parent bb0ece6 commit dd8091d
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions extension/src/experiments/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { getRelativePattern } from '../../fileSystem/relativePattern'
import { createFileSystemWatcher } from '../../fileSystem/watcher'
import { AvailableCommands, InternalCommands } from '../../commands/internal'
import { ExpShowOutput } from '../../cli/dvc/contract'
import { EXPERIMENT_WORKSPACE_ID, ExpShowOutput } from '../../cli/dvc/contract'
import { BaseData } from '../../data'
import { DOT_DVC, ExperimentFlag } from '../../cli/dvc/constants'
import { gitPath } from '../../cli/git/constants'
Expand Down Expand Up @@ -47,32 +47,34 @@ export class ExperimentsData extends BaseData<ExpShowOutput> {
)

void this.updateAvailableBranchesToSelect(allBranches)
const data: ExpShowOutput = []

const { branches, currentBranch } = await this.getBranchesToShowWithCurrent(
allBranches
)

const flags = []
const branchList: string[] = []

for (const branch of branches) {
const nbOfCommitsToShow = this.experiments.getNbOfCommitsToShow(branch)
for (let i = 0; i < nbOfCommitsToShow; i++) {
flags.push(ExperimentFlag.REV, `${branch}~${i}`)
branchList.push(branch)
}
}

const data = await this.internalCommands.executeCommand<ExpShowOutput>(
AvailableCommands.EXP_SHOW,
this.dvcRoot,
...flags
)

// eslint-disable-next-line unicorn/no-array-for-each
data.forEach(
(output, i) =>
(output.branch = i === 0 ? currentBranch : branchList[i - 1])
await Promise.all(
branches.map(async branch => {
const branchFlags = [
ExperimentFlag.REV,
branch,
ExperimentFlag.NUM_COMMIT,
this.experiments.getNbOfCommitsToShow(branch).toString()
]

const output = (await this.expShow(
branchFlags,
branch
)) as ExpShowOutput

if (branch !== currentBranch) {
const workspaceIndex = output.findIndex(
exp => exp.rev === EXPERIMENT_WORKSPACE_ID
)
output.splice(workspaceIndex, 1)
}
data.push(...output)
})
)

this.collectFiles(data)
Expand Down Expand Up @@ -101,6 +103,15 @@ export class ExperimentsData extends BaseData<ExpShowOutput> {
return { branches, currentBranch }
}

private async expShow(flags: (ExperimentFlag | string)[], branch?: string) {
const data = await this.internalCommands.executeCommand<ExpShowOutput>(
AvailableCommands.EXP_SHOW,
this.dvcRoot,
...flags
)
return data.map(exp => ({ ...exp, branch }))
}

private async updateAvailableBranchesToSelect(branches?: string[]) {
const allBranches =
branches ||
Expand Down

0 comments on commit dd8091d

Please sign in to comment.