Skip to content

Commit d7b0c58

Browse files
authored
Update collection of files which trigger exp show updates (#4564)
1 parent 375beaa commit d7b0c58

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

extension/src/experiments/data/collect.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ import { generateTestExpShowOutput } from '../../test/util/experiments'
66

77
describe('collectFiles', () => {
88
it('should collect all of the available files from the test fixture', () => {
9-
expect(collectFiles(expShowFixture, [])).toStrictEqual([
10-
'params.yaml',
9+
const files = collectFiles(expShowFixture, [])
10+
files.sort()
11+
12+
expect(files).toStrictEqual([
13+
'metrics.json',
1114
join('nested', 'params.yaml'),
15+
'params.yaml',
1216
'summary.json'
1317
])
1418
})
@@ -80,9 +84,12 @@ describe('collectFiles', () => {
8084
}
8185
})
8286

87+
const files = collectFiles(workspaceOnly, ['dvclive.json'])
88+
files.sort()
89+
8390
expect(collectFiles(workspaceOnly, ['dvclive.json'])).toStrictEqual([
84-
'params.yaml',
85-
'dvclive.json'
91+
'dvclive.json',
92+
'params.yaml'
8693
])
8794
})
8895
})

extension/src/experiments/data/collect.ts

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1-
import { ExpShowOutput } from '../../cli/dvc/contract'
2-
import { uniqueValues } from '../../util/array'
1+
import { ExpData, ExpShowOutput, MetricsOrParams } from '../../cli/dvc/contract'
32
import { getExpData } from '../columns/collect'
43

4+
const collectFilesFromKeys = (
5+
acc: Set<string>,
6+
metricsOrParams: MetricsOrParams | null | undefined
7+
): void => {
8+
for (const file of Object.keys(metricsOrParams || {})) {
9+
if (!file) {
10+
continue
11+
}
12+
acc.add(file)
13+
}
14+
}
15+
16+
const collectFilesFromExperiment = (
17+
acc: Set<string>,
18+
data: ExpData | undefined
19+
) => {
20+
if (!data) {
21+
return
22+
}
23+
collectFilesFromKeys(acc, data.params)
24+
collectFilesFromKeys(acc, data.metrics)
25+
}
26+
527
export const collectFiles = (
628
output: ExpShowOutput,
729
existingFiles: string[]
@@ -10,17 +32,25 @@ export const collectFiles = (
1032
return existingFiles
1133
}
1234

13-
const [workspace] = output
35+
const acc = new Set(existingFiles)
1436

15-
const data = getExpData(workspace)
37+
for (const commit of output) {
38+
const data = getExpData(commit)
39+
collectFilesFromExperiment(acc, data)
40+
41+
const { experiments } = commit
42+
43+
if (!experiments?.length) {
44+
continue
45+
}
46+
47+
for (const { revs } of experiments) {
48+
const [experiment] = revs
49+
collectFilesFromExperiment(acc, getExpData(experiment))
50+
}
51+
}
1652

17-
return uniqueValues([
18-
...Object.keys({
19-
...data?.params,
20-
...data?.metrics
21-
}).filter(Boolean),
22-
...existingFiles
23-
])
53+
return [...acc]
2454
}
2555

2656
const isCurrentBranch = (branch: string) => branch.indexOf('*') === 0

0 commit comments

Comments
 (0)