Skip to content
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

Refresh cached plots data on every update #3532

Merged
merged 3 commits into from
Apr 2, 2023
Merged

Conversation

mattseddon
Copy link
Member

@mattseddon mattseddon commented Mar 22, 2023

4/4 main <- #3477 <- #3520 <- #3522 <- this

Closes #2277. Patches this problem.

Tl;dr of the problem is that our cached plots data is actually mutable depending on the combination of revisions (and even order of those revisions) that we call the plots diff with.

This PR updates the way that we treat cached plots data in the extension. Now every time there is an update to the selected revisions we call for an update from the CLI. Please watch the demo plus read below to see the approach that I've taken.

LMK what you think.

Demo

Screen.Recording.2023-03-23.at.9.37.46.pm.mov

The way that it works.

  1. We get a call to update the data from one of the paths available (e.g change in selected revisions or change in data in the workspace).
  2. We send all the data that we currently have cached to the UI.
  3. At the same time we call the CLI for an update for all of the currently selected revisions.
  4. We send the updated data to the UI.

This approach gives us a few of things:

  1. It gives the user something to look whilst the CLI is working.
  2. It gives them the impression that something is happening.
  3. In most cases the initial data send to the UI will be correct anyway.
  4. The resultant data should always be correct.

@mattseddon mattseddon added the bug Something isn't working label Mar 22, 2023
@mattseddon mattseddon self-assigned this Mar 22, 2023
@mattseddon mattseddon force-pushed the drop-cache-on-update branch from 26cb1df to 7fe2670 Compare March 22, 2023 09:24
@mattseddon mattseddon changed the base branch from main to show-tree-errors March 22, 2023 09:30
@mattseddon mattseddon changed the base branch from show-tree-errors to main March 23, 2023 10:15
@mattseddon mattseddon force-pushed the drop-cache-on-update branch from 7fe2670 to e92b897 Compare March 23, 2023 10:36
@mattseddon mattseddon changed the title Drop cached plots data whenever dvc.yaml is changed Refresh cached plots data on every update Mar 23, 2023
@mattseddon mattseddon changed the base branch from main to show-tree-errors March 23, 2023 10:37
@@ -450,12 +450,6 @@ export class Experiments extends BaseRepository<TableData> {
return experiment?.name || experiment?.label
}

public getMutableRevisions() {
Copy link
Member Author

@mattseddon mattseddon Mar 24, 2023

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.

this.model.getMissingRevisions(),
this.model.getMutableRevisions()
)
this.notifyTriggered()
Copy link
Member Author

Choose a reason for hiding this comment

The 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.

private onDidTriggerDataUpdate() {
const sendCachedDataToWebview = () => {
this.plots.resetFetched()
this.plots.setComparisonOrder()
Copy link
Member Author

Choose a reason for hiding this comment

The 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

@@ -355,6 +336,12 @@ export class PlotsModel extends ModelWithPersistence {
return this.experiments.getSelectedRevisions().map(({ label }) => label)
}

public getSelectedOrderedCliIds() {
return collectOrderedRevisions(this.experiments.getSelectedRevisions()).map(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] This logic should give stable semantics no matter what order the user selects the experiments. We will take the most recent version of the template and try to apply that to the rest of the data.

@@ -355,6 +336,12 @@ export class PlotsModel extends ModelWithPersistence {
return this.experiments.getSelectedRevisions().map(({ label }) => label)
}

public getSelectedOrderedCliIds() {
return collectOrderedRevisions(this.experiments.getSelectedRevisions()).map(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[F] This logic should give stable semantics no matter what order the user selects the experiments. We will take the most recent version of the template and try to apply that to the rest of the data.

Copy link
Contributor

@julieg18 julieg18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

Base automatically changed from show-tree-errors to main April 2, 2023 02:08
@mattseddon mattseddon force-pushed the drop-cache-on-update branch from b0dd757 to 72be7b6 Compare April 2, 2023 02:14
@mattseddon mattseddon force-pushed the drop-cache-on-update branch from 72be7b6 to 02e94b4 Compare April 2, 2023 02:15
@mattseddon mattseddon enabled auto-merge (squash) April 2, 2023 02:20
@@ -23,7 +23,7 @@ interface CustomPlotsProps {

export const CustomPlots: React.FC<CustomPlotsProps> = ({ plotsIds }) => {
const [order, setOrder] = useState(plotsIds)
const { nbItemsPerRow, hasData, disabledDragPlotIds } = useSelector(
const { nbItemsPerRow, hasData, hasItems, disabledDragPlotIds } = useSelector(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

@@ -7,12 +7,9 @@ import { PlotsContainer } from '../PlotsContainer'
import { PlotsState } from '../../store'

export const TemplatePlotsWrapper: React.FC = () => {
const { nbItemsPerRow, isCollapsed, height } = useSelector(
const { nbItemsPerRow, isCollapsed, height, hasItems } = useSelector(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 4 locations. Consider refactoring.

@codeclimate
Copy link

codeclimate bot commented Apr 2, 2023

Code Climate has analyzed commit 02e94b4 and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

The test coverage on the diff in this pull request is 100.0% (85% is the threshold).

This pull request will bring the total coverage in the repository to 95.1%.

View more on Code Climate.

@mattseddon mattseddon merged commit 6bdd98c into main Apr 2, 2023
@mattseddon mattseddon deleted the drop-cache-on-update branch April 2, 2023 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image plots show proper message and disable button if image is not available
3 participants