Skip to content

Commit 31b7a01

Browse files
authored
Do not block data from going to webview after fetching once (#1727)
1 parent 516ba13 commit 31b7a01

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

extension/src/data/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { definedAndNonEmpty, sameContents, uniqueValues } from '../util/array'
99
import { DeferredDisposable } from '../class/deferred'
1010

1111
export abstract class BaseData<
12-
T extends PlotsOutput | ExperimentsOutput
12+
T extends { data: PlotsOutput; revs: string[] } | ExperimentsOutput
1313
> extends DeferredDisposable {
1414
public readonly onDidUpdate: Event<T>
1515

extension/src/plots/data/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '../../util/array'
1010
import { PlotsModel } from '../model'
1111

12-
export class PlotsData extends BaseData<PlotsOutput> {
12+
export class PlotsData extends BaseData<{ data: PlotsOutput; revs: string[] }> {
1313
private model?: PlotsModel
1414

1515
constructor(
@@ -26,7 +26,7 @@ export class PlotsData extends BaseData<PlotsOutput> {
2626
}
2727

2828
public async update(): Promise<void> {
29-
const revisions = flattenUnique([
29+
const revs = flattenUnique([
3030
this.model?.getMissingRevisions() || [],
3131
this.model?.getMutableRevisions() || []
3232
])
@@ -35,31 +35,31 @@ export class PlotsData extends BaseData<PlotsOutput> {
3535
(await this.internalCommands.executeCommand<boolean>(
3636
AvailableCommands.IS_EXPERIMENT_RUNNING
3737
)) &&
38-
!definedAndNonEmpty(revisions)
38+
!definedAndNonEmpty(revs)
3939
) {
4040
return
4141
}
4242

43-
const args = sameContents(revisions, ['workspace']) ? [] : revisions
43+
const args = sameContents(revs, ['workspace']) ? [] : revs
4444

4545
const data = await this.internalCommands.executeCommand<PlotsOutput>(
4646
AvailableCommands.PLOTS_DIFF,
4747
this.dvcRoot,
4848
...args
4949
)
5050

51-
const files = this.collectFiles(data)
51+
const files = this.collectFiles({ data })
5252

5353
this.compareFiles(files)
5454

55-
return this.notifyChanged(data)
55+
return this.notifyChanged({ data, revs })
5656
}
5757

5858
public managedUpdate() {
5959
return this.processManager.run('update')
6060
}
6161

62-
public collectFiles(data: PlotsOutput) {
62+
public collectFiles({ data }: { data: PlotsOutput }) {
6363
return Object.keys(data)
6464
}
6565

extension/src/plots/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ export class Plots extends BaseRepository<TPlotsData> {
6363
)
6464

6565
this.dispose.track(
66-
this.data.onDidUpdate(async data => {
66+
this.data.onDidUpdate(async ({ data, revs }) => {
6767
await Promise.all([
68-
this.plots?.transformAndSetPlots(data),
68+
this.plots?.transformAndSetPlots(data, revs),
6969
this.paths?.transformAndSet(data)
7070
])
7171
this.notifyChanged()
@@ -156,7 +156,7 @@ export class Plots extends BaseRepository<TPlotsData> {
156156

157157
if (
158158
this.paths?.hasPaths() &&
159-
definedAndNonEmpty(this.plots?.getMissingRevisions())
159+
definedAndNonEmpty(this.plots?.getUnfetchedRevisions())
160160
) {
161161
this.sendCheckpointPlotsData()
162162
return this.data.managedUpdate()

extension/src/plots/model/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ export class PlotsModel extends ModelWithPersistence {
4141
private branchRevisions: Record<string, string> = {}
4242
private workspaceRunningCheckpoint: string | undefined
4343

44+
private fetchedRevs = new Set<string>()
45+
4446
private comparisonData: ComparisonData = {}
4547
private comparisonOrder: string[]
4648

@@ -97,7 +99,9 @@ export class PlotsModel extends ModelWithPersistence {
9799
return this.removeStaleData()
98100
}
99101

100-
public async transformAndSetPlots(data: PlotsOutput) {
102+
public async transformAndSetPlots(data: PlotsOutput, revs: string[]) {
103+
this.fetchedRevs = new Set([...this.fetchedRevs, ...revs])
104+
101105
const [{ comparisonData, revisionData }, templates] = await Promise.all([
102106
collectData(data),
103107
collectTemplates(data)
@@ -153,6 +157,12 @@ export class PlotsModel extends ModelWithPersistence {
153157
}
154158
}
155159

160+
public getUnfetchedRevisions() {
161+
return this.getSelectedRevisions().filter(
162+
revision => !this.fetchedRevs.has(revision)
163+
)
164+
}
165+
156166
public getMissingRevisions() {
157167
const cachedRevisions = new Set([
158168
...Object.keys(this.comparisonData),
@@ -306,6 +316,7 @@ export class PlotsModel extends ModelWithPersistence {
306316
if (sha && this.branchRevisions[id] !== sha) {
307317
delete this.revisionData[id]
308318
delete this.comparisonData[id]
319+
this.fetchedRevs.delete(id)
309320
this.branchRevisions[id] = sha
310321
}
311322
}

0 commit comments

Comments
 (0)