diff --git a/extension/src/data/index.ts b/extension/src/data/index.ts index 6f13edce69..62af3504f4 100644 --- a/extension/src/data/index.ts +++ b/extension/src/data/index.ts @@ -9,7 +9,7 @@ import { definedAndNonEmpty, sameContents, uniqueValues } from '../util/array' import { DeferredDisposable } from '../class/deferred' export abstract class BaseData< - T extends PlotsOutput | ExperimentsOutput + T extends { data: PlotsOutput; revs: string[] } | ExperimentsOutput > extends DeferredDisposable { public readonly onDidUpdate: Event diff --git a/extension/src/plots/data/index.ts b/extension/src/plots/data/index.ts index 6d2f6c75f5..6262dc42a0 100644 --- a/extension/src/plots/data/index.ts +++ b/extension/src/plots/data/index.ts @@ -9,7 +9,7 @@ import { } from '../../util/array' import { PlotsModel } from '../model' -export class PlotsData extends BaseData { +export class PlotsData extends BaseData<{ data: PlotsOutput; revs: string[] }> { private model?: PlotsModel constructor( @@ -26,7 +26,7 @@ export class PlotsData extends BaseData { } public async update(): Promise { - const revisions = flattenUnique([ + const revs = flattenUnique([ this.model?.getMissingRevisions() || [], this.model?.getMutableRevisions() || [] ]) @@ -35,12 +35,12 @@ export class PlotsData extends BaseData { (await this.internalCommands.executeCommand( AvailableCommands.IS_EXPERIMENT_RUNNING )) && - !definedAndNonEmpty(revisions) + !definedAndNonEmpty(revs) ) { return } - const args = sameContents(revisions, ['workspace']) ? [] : revisions + const args = sameContents(revs, ['workspace']) ? [] : revs const data = await this.internalCommands.executeCommand( AvailableCommands.PLOTS_DIFF, @@ -48,18 +48,18 @@ export class PlotsData extends BaseData { ...args ) - const files = this.collectFiles(data) + const files = this.collectFiles({ data }) this.compareFiles(files) - return this.notifyChanged(data) + return this.notifyChanged({ data, revs }) } public managedUpdate() { return this.processManager.run('update') } - public collectFiles(data: PlotsOutput) { + public collectFiles({ data }: { data: PlotsOutput }) { return Object.keys(data) } diff --git a/extension/src/plots/index.ts b/extension/src/plots/index.ts index 44b9a303cd..af495a1ac4 100644 --- a/extension/src/plots/index.ts +++ b/extension/src/plots/index.ts @@ -63,9 +63,9 @@ export class Plots extends BaseRepository { ) this.dispose.track( - this.data.onDidUpdate(async data => { + this.data.onDidUpdate(async ({ data, revs }) => { await Promise.all([ - this.plots?.transformAndSetPlots(data), + this.plots?.transformAndSetPlots(data, revs), this.paths?.transformAndSet(data) ]) this.notifyChanged() @@ -156,7 +156,7 @@ export class Plots extends BaseRepository { if ( this.paths?.hasPaths() && - definedAndNonEmpty(this.plots?.getMissingRevisions()) + definedAndNonEmpty(this.plots?.getUnfetchedRevisions()) ) { this.sendCheckpointPlotsData() return this.data.managedUpdate() diff --git a/extension/src/plots/model/index.ts b/extension/src/plots/model/index.ts index a98cc545f0..09d9e54b01 100644 --- a/extension/src/plots/model/index.ts +++ b/extension/src/plots/model/index.ts @@ -41,6 +41,8 @@ export class PlotsModel extends ModelWithPersistence { private branchRevisions: Record = {} private workspaceRunningCheckpoint: string | undefined + private fetchedRevs = new Set() + private comparisonData: ComparisonData = {} private comparisonOrder: string[] @@ -97,7 +99,9 @@ export class PlotsModel extends ModelWithPersistence { return this.removeStaleData() } - public async transformAndSetPlots(data: PlotsOutput) { + public async transformAndSetPlots(data: PlotsOutput, revs: string[]) { + this.fetchedRevs = new Set([...this.fetchedRevs, ...revs]) + const [{ comparisonData, revisionData }, templates] = await Promise.all([ collectData(data), collectTemplates(data) @@ -153,6 +157,12 @@ export class PlotsModel extends ModelWithPersistence { } } + public getUnfetchedRevisions() { + return this.getSelectedRevisions().filter( + revision => !this.fetchedRevs.has(revision) + ) + } + public getMissingRevisions() { const cachedRevisions = new Set([ ...Object.keys(this.comparisonData), @@ -306,6 +316,7 @@ export class PlotsModel extends ModelWithPersistence { if (sha && this.branchRevisions[id] !== sha) { delete this.revisionData[id] delete this.comparisonData[id] + this.fetchedRevs.delete(id) this.branchRevisions[id] = sha } }