Skip to content

Commit bb6b564

Browse files
authored
Run remote experiments data update in the background (#4342)
1 parent f206aad commit bb6b564

File tree

16 files changed

+170
-155
lines changed

16 files changed

+170
-155
lines changed

extension/src/data/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ import { uniqueValues } from '../util/array'
99
import { DeferredDisposable } from '../class/deferred'
1010
import { isPathInSubProject, isSameOrChild } from '../fileSystem'
1111

12-
export type ExperimentsOutput = {
12+
type LocalExperimentsOutput = {
1313
availableNbCommits: { [branch: string]: number }
1414
expShow: ExpShowOutput
1515
gitLog: string
16-
remoteExpRefs: string
1716
rowOrder: { branch: string; sha: string }[]
1817
}
1918

19+
type RemoteExperimentsOutput = { remoteExpRefs: string }
20+
21+
export type ExperimentsOutput = LocalExperimentsOutput | RemoteExperimentsOutput
22+
23+
export const isRemoteExperimentsOutput = (
24+
data: ExperimentsOutput
25+
): data is RemoteExperimentsOutput =>
26+
(data as RemoteExperimentsOutput).remoteExpRefs !== undefined
27+
2028
export abstract class BaseData<
2129
T extends
2230
| { data: PlotsOutputOrError; revs: string[] }
@@ -58,15 +66,13 @@ export abstract class BaseData<
5866
this.staticFiles = staticFiles
5967

6068
this.watchFiles()
61-
62-
this.waitForInitialData()
6369
}
6470

6571
protected notifyChanged(data: T) {
6672
this.updated.fire(data)
6773
}
6874

69-
private waitForInitialData() {
75+
protected waitForInitialData() {
7076
const waitForInitialData = this.dispose.track(
7177
this.onDidUpdate(() => {
7278
this.dispose.untrack(waitForInitialData)

extension/src/experiments/data/index.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import { getRelativePattern } from '../../fileSystem/relativePattern'
88
import { createFileSystemWatcher } from '../../fileSystem/watcher'
99
import { AvailableCommands, InternalCommands } from '../../commands/internal'
1010
import { ExpShowOutput } from '../../cli/dvc/contract'
11-
import { BaseData, ExperimentsOutput } from '../../data'
11+
import {
12+
BaseData,
13+
ExperimentsOutput,
14+
isRemoteExperimentsOutput
15+
} from '../../data'
1216
import { Args, DOT_DVC, ExperimentFlag } from '../../cli/dvc/constants'
1317
import { COMMITS_SEPARATOR, gitPath } from '../../cli/git/constants'
1418
import { getGitPath } from '../../fileSystem'
@@ -35,23 +39,18 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
3539

3640
void this.watchExpGitRefs()
3741
void this.managedUpdate()
42+
this.waitForInitialLocalData()
3843
}
3944

4045
public managedUpdate() {
4146
return this.processManager.run('update')
4247
}
4348

4449
public async update(): Promise<void> {
45-
const [{ availableNbCommits, expShow, gitLog, rowOrder }, remoteExpRefs] =
46-
await Promise.all([this.updateExpShow(), this.updateRemoteExpRefs()])
47-
48-
return this.notifyChanged({
49-
availableNbCommits,
50-
expShow,
51-
gitLog,
52-
remoteExpRefs,
53-
rowOrder
54-
})
50+
await Promise.all([
51+
this.notifyChanged(await this.updateExpShow()),
52+
this.notifyChanged(await this.updateRemoteExpRefs())
53+
])
5554
}
5655

5756
private async updateExpShow() {
@@ -162,10 +161,27 @@ export class ExperimentsData extends BaseData<ExperimentsOutput> {
162161
)
163162
}
164163

165-
private updateRemoteExpRefs() {
166-
return this.internalCommands.executeCommand(
167-
AvailableCommands.GIT_GET_REMOTE_EXPERIMENT_REFS,
168-
this.dvcRoot
164+
private async updateRemoteExpRefs() {
165+
const [remoteExpRefs] = await Promise.all([
166+
this.internalCommands.executeCommand(
167+
AvailableCommands.GIT_GET_REMOTE_EXPERIMENT_REFS,
168+
this.dvcRoot
169+
),
170+
this.isReady()
171+
])
172+
return { remoteExpRefs }
173+
}
174+
175+
private waitForInitialLocalData() {
176+
const waitForInitialData = this.dispose.track(
177+
this.onDidUpdate(data => {
178+
if (isRemoteExperimentsOutput(data)) {
179+
return
180+
}
181+
this.dispose.untrack(waitForInitialData)
182+
waitForInitialData.dispose()
183+
this.deferred.resolve()
184+
})
169185
)
170186
}
171187
}

extension/src/experiments/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import { DecorationProvider } from './model/decorationProvider'
3333
import { starredFilter } from './model/filterBy/constants'
3434
import { ResourceLocator } from '../resourceLocator'
3535
import { AvailableCommands, InternalCommands } from '../commands/internal'
36-
import { ExperimentsOutput } from '../data'
36+
import { ExperimentsOutput, isRemoteExperimentsOutput } from '../data'
3737
import { ViewKey } from '../webview/constants'
3838
import { BaseRepository } from '../webview/repository'
3939
import { Title } from '../vscode/title'
@@ -173,24 +173,25 @@ export class Experiments extends BaseRepository<TableData> {
173173
return this.data.managedUpdate()
174174
}
175175

176-
public async setState({
177-
availableNbCommits,
178-
expShow,
179-
gitLog,
180-
rowOrder,
181-
remoteExpRefs
182-
}: ExperimentsOutput) {
176+
public async setState(data: ExperimentsOutput) {
177+
if (isRemoteExperimentsOutput(data)) {
178+
const { remoteExpRefs } = data
179+
this.experiments.transformAndSetRemote(remoteExpRefs)
180+
return this.webviewMessages.sendWebviewMessage()
181+
}
182+
183+
const { expShow, gitLog, rowOrder, availableNbCommits } = data
184+
183185
const hadCheckpoints = this.hasCheckpoints()
184186
const dvcLiveOnly = await this.checkSignalFile()
185187
await Promise.all([
186188
this.columns.transformAndSet(expShow),
187-
this.experiments.transformAndSet(
189+
this.experiments.transformAndSetLocal(
188190
expShow,
189191
gitLog,
190192
dvcLiveOnly,
191193
rowOrder,
192-
availableNbCommits,
193-
remoteExpRefs
194+
availableNbCommits
194195
)
195196
])
196197

@@ -206,9 +207,10 @@ export class Experiments extends BaseRepository<TableData> {
206207
return this.notifyChanged()
207208
}
208209

209-
public unsetPushing(ids: string[]) {
210+
public async unsetPushing(ids: string[]) {
211+
await this.update()
210212
this.experiments.unsetPushing(ids)
211-
return this.update()
213+
return this.notifyChanged()
212214
}
213215

214216
public hasCheckpoints() {
@@ -579,7 +581,7 @@ export class Experiments extends BaseRepository<TableData> {
579581
private setupInitialData() {
580582
const waitForInitialData = this.dispose.track(
581583
this.onDidChangeExperiments(async () => {
582-
await this.pipeline.isReady()
584+
await Promise.all([this.data.isReady(), this.pipeline.isReady()])
583585
this.deferred.resolve()
584586
this.dispose.untrack(waitForInitialData)
585587
waitForInitialData.dispose()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { collectExperiments } from './collect'
22
import { generateTestExpShowOutput } from '../../test/util/experiments'
33
import { ExpShowOutput } from '../../cli/dvc/contract'
44

5-
const DEFAULT_DATA: [string, boolean, string] = ['', false, '']
5+
const DEFAULT_DATA: [string, boolean] = ['', false]
66

77
describe('collectExperiments', () => {
88
it('should return an empty array if no commits are present', () => {
@@ -13,7 +13,7 @@ describe('collectExperiments', () => {
1313
expect(commits).toStrictEqual([])
1414
})
1515

16-
const expShowWithTwoCommits: [ExpShowOutput, string, boolean, string] = [
16+
const expShowWithTwoCommits: [ExpShowOutput, string, boolean] = [
1717
generateTestExpShowOutput(
1818
{},
1919
{

extension/src/experiments/model/collect.ts

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { extractColumns } from '../columns/extract'
99
import {
1010
CommitData,
1111
Experiment,
12-
GitRemoteStatus,
1312
RunningExperiment,
1413
isQueued,
1514
isRunning
@@ -235,21 +234,6 @@ const collectExecutorInfo = (
235234
}
236235
}
237236

238-
const collectRemoteStatus = (
239-
experiment: Experiment,
240-
remoteExpShas: Set<string>
241-
): void => {
242-
if (
243-
!experiment.sha ||
244-
![undefined, ExperimentStatus.SUCCESS].includes(experiment.status)
245-
) {
246-
return
247-
}
248-
experiment.gitRemoteStatus = remoteExpShas.has(experiment.sha)
249-
? GitRemoteStatus.ON_REMOTE
250-
: GitRemoteStatus.NOT_ON_REMOTE
251-
}
252-
253237
const collectRunningExperiment = (
254238
acc: ExperimentsAccumulator,
255239
experiment: Experiment
@@ -266,8 +250,7 @@ const collectRunningExperiment = (
266250
const collectExpRange = (
267251
acc: ExperimentsAccumulator,
268252
baseline: Experiment,
269-
expRange: ExpRange,
270-
remoteExpShas: Set<string>
253+
expRange: ExpRange
271254
): void => {
272255
const { revs, executor } = expRange
273256
if (!revs?.length) {
@@ -307,7 +290,6 @@ const collectExpRange = (
307290
}
308291

309292
collectExecutorInfo(experiment, executor)
310-
collectRemoteStatus(experiment, remoteExpShas)
311293
collectRunningExperiment(acc, experiment)
312294

313295
addToMapArray(acc.experimentsByCommit, baselineId, experiment)
@@ -359,20 +341,10 @@ const collectCliError = (
359341
}
360342
}
361343

362-
const collectRemoteExpShas = (remoteExpRefs: string): Set<string> => {
363-
const remoteExpShas = new Set<string>()
364-
for (const ref of trimAndSplit(remoteExpRefs)) {
365-
const [sha] = ref.split(/\s/)
366-
remoteExpShas.add(sha)
367-
}
368-
return remoteExpShas
369-
}
370-
371344
export const collectExperiments = (
372345
expShow: ExpShowOutput,
373346
gitLog: string,
374-
dvcLiveOnly: boolean,
375-
remoteExpRefs: string
347+
dvcLiveOnly: boolean
376348
): ExperimentsAccumulator => {
377349
const acc: ExperimentsAccumulator = {
378350
cliError: undefined,
@@ -387,7 +359,6 @@ export const collectExperiments = (
387359
}
388360

389361
const commitData = collectCommitsData(gitLog)
390-
const remoteExpShas = collectRemoteExpShas(remoteExpRefs)
391362

392363
for (const expState of expShow) {
393364
const baseline = collectExpState(acc, expState, commitData)
@@ -398,7 +369,7 @@ export const collectExperiments = (
398369
}
399370

400371
for (const expRange of experiments) {
401-
collectExpRange(acc, baseline, expRange, remoteExpShas)
372+
collectExpRange(acc, baseline, expRange)
402373
}
403374
}
404375

@@ -534,3 +505,12 @@ export const collectBranches = (
534505

535506
return { branches, currentBranch }
536507
}
508+
509+
export const collectRemoteExpShas = (remoteExpRefs: string): Set<string> => {
510+
const remoteExpShas = new Set<string>()
511+
for (const ref of trimAndSplit(remoteExpRefs)) {
512+
const [sha] = ref.split(/\s/)
513+
remoteExpShas.add(sha)
514+
}
515+
return remoteExpShas
516+
}

0 commit comments

Comments
 (0)