-
Notifications
You must be signed in to change notification settings - Fork 28
Refresh cached plots data on every update #3532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { EventEmitter } from 'vscode' | ||
| import { collectMetricsFiles, collectFiles, collectRevs } from './collect' | ||
| import { Event, EventEmitter } from 'vscode' | ||
| import { collectMetricsFiles, collectFiles } from './collect' | ||
| import { | ||
| EXPERIMENT_WORKSPACE_ID, | ||
| ExperimentsOutput, | ||
|
|
@@ -14,10 +14,16 @@ export class PlotsData extends BaseData<{ | |
| data: PlotsOutputOrError | ||
| revs: string[] | ||
| }> { | ||
| public readonly onDidTrigger: Event<void> | ||
|
|
||
| private readonly model: PlotsModel | ||
|
|
||
| private metricFiles: string[] = [] | ||
|
|
||
| private readonly triggered: EventEmitter<void> = this.dispose.track( | ||
| new EventEmitter() | ||
| ) | ||
|
|
||
| constructor( | ||
| dvcRoot: string, | ||
| internalCommands: InternalCommands, | ||
|
|
@@ -37,13 +43,12 @@ export class PlotsData extends BaseData<{ | |
| ['dvc.yaml', 'dvc.lock'] | ||
| ) | ||
| this.model = model | ||
| this.onDidTrigger = this.triggered.event | ||
| } | ||
|
|
||
| public async update(): Promise<void> { | ||
| const revs = collectRevs( | ||
| this.model.getMissingRevisions(), | ||
| this.model.getMutableRevisions() | ||
| ) | ||
| this.notifyTriggered() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] This is how we send the cached data before following up with a CLI update. |
||
| const revs = this.model.getSelectedOrderedCliIds() | ||
|
|
||
| const args = this.getArgs(revs) | ||
| const data = await this.internalCommands.executeCommand<PlotsOutputOrError>( | ||
|
|
@@ -76,6 +81,10 @@ export class PlotsData extends BaseData<{ | |
| this.collectedFiles = collectFiles(data, this.collectedFiles) | ||
| } | ||
|
|
||
| private notifyTriggered() { | ||
| this.triggered.fire() | ||
| } | ||
|
|
||
| private getArgs(revs: string[]) { | ||
| const cliWillThrowError = sameContents(revs, [EXPERIMENT_WORKSPACE_ID]) | ||
| if (this.model && cliWillThrowError) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,6 @@ import { BaseRepository } from '../webview/repository' | |
| import { Experiments } from '../experiments' | ||
| import { Resource } from '../resourceLocator' | ||
| import { InternalCommands } from '../commands/internal' | ||
| import { definedAndNonEmpty } from '../util/array' | ||
| import { TEMP_PLOTS_DIR } from '../cli/dvc/constants' | ||
| import { removeDir } from '../fileSystem' | ||
| import { Toast } from '../vscode/toast' | ||
|
|
@@ -69,6 +68,7 @@ export class Plots extends BaseRepository<TPlotsData> { | |
| new PlotsData(dvcRoot, internalCommands, this.plots, updatesPaused) | ||
| ) | ||
|
|
||
| this.onDidTriggerDataUpdate() | ||
| this.onDidUpdateData() | ||
| this.waitForInitialData(experiments) | ||
|
|
||
|
|
@@ -105,10 +105,7 @@ export class Plots extends BaseRepository<TPlotsData> { | |
| void Toast.infoWithOptions( | ||
| 'Attempting to refresh plots for selected experiments.' | ||
| ) | ||
| for (const { revision } of this.plots.getSelectedRevisionDetails()) { | ||
| this.plots.setupManualRefresh(revision) | ||
| } | ||
| void this.data.managedUpdate() | ||
| this.triggerDataUpdate() | ||
| } | ||
|
|
||
| public getChildPaths(path: string | undefined) { | ||
|
|
@@ -130,7 +127,7 @@ export class Plots extends BaseRepository<TPlotsData> { | |
| } | ||
|
|
||
| protected sendInitialWebviewData() { | ||
| return this.fetchMissingOrSendPlots() | ||
| return this.sendPlots() | ||
| } | ||
|
|
||
| private notifyChanged() { | ||
|
|
@@ -140,19 +137,18 @@ export class Plots extends BaseRepository<TPlotsData> { | |
| this.errors.getErrorPaths(selectedRevisions) | ||
| ) | ||
| this.pathsChanged.fire() | ||
| void this.fetchMissingOrSendPlots() | ||
|
|
||
| if (this.plots.requiresUpdate()) { | ||
| this.triggerDataUpdate() | ||
| return | ||
| } | ||
|
|
||
| void this.sendPlots() | ||
| } | ||
|
|
||
| private async fetchMissingOrSendPlots() { | ||
| private async sendPlots() { | ||
| await this.isReady() | ||
|
|
||
| if ( | ||
| this.paths.hasPaths() && | ||
| definedAndNonEmpty(this.plots.getUnfetchedRevisions()) | ||
| ) { | ||
| void this.data.managedUpdate() | ||
| } | ||
|
|
||
| return this.webviewMessages.sendWebviewMessage() | ||
| } | ||
|
|
||
|
|
@@ -214,7 +210,7 @@ export class Plots extends BaseRepository<TPlotsData> { | |
|
|
||
| private async initializeData() { | ||
| await this.plots.transformAndSetExperiments() | ||
| void this.data.managedUpdate() | ||
| this.triggerDataUpdate() | ||
| await Promise.all([ | ||
| this.data.isReady(), | ||
| this.plots.isReady(), | ||
|
|
@@ -223,6 +219,19 @@ export class Plots extends BaseRepository<TPlotsData> { | |
| this.deferred.resolve() | ||
| } | ||
|
|
||
| private triggerDataUpdate() { | ||
| void this.data.managedUpdate() | ||
| } | ||
|
|
||
| private onDidTriggerDataUpdate() { | ||
| const sendCachedDataToWebview = () => { | ||
| this.plots.resetFetched() | ||
| this.plots.setComparisonOrder() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [F] Resetting the fetchedRevs means that we get spinners in the ribbon for all of the revisions. Setting the comparison order means we get a loading state for the comparison table: Screen.Recording.2023-03-24.at.11.33.54.am.mov |
||
| return this.sendPlots() | ||
| } | ||
| this.dispose.track(this.data.onDidTrigger(() => sendCachedDataToWebview())) | ||
| } | ||
|
|
||
| private onDidUpdateData() { | ||
| this.dispose.track( | ||
| this.data.onDidUpdate(async ({ data, revs }) => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[F] No longer required as we now refresh all selected revisions all the time.