Skip to content

Conversation

@franciscojma86
Copy link
Contributor

Description

visual_studio.dart is not keeping track whether it has queried vswhere and didn't find an installation, of it hasn't performed any queries at all. This may cause unnecessary queries on the former case. This PR assigns a sentinel value of an empty map to the cached installation details to avoid repeating the queries.

Related Issues

#40196

Tests

I added the following tests:

This is a refactor so the behavior should continue as before.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read [Handling breaking changes]). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@codecov
Copy link

codecov bot commented Sep 11, 2019

Codecov Report

Merging #40197 into master will increase coverage by 0.35%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #40197      +/-   ##
==========================================
+ Coverage   58.44%    58.8%   +0.35%     
==========================================
  Files         192      192              
  Lines       18627    18636       +9     
==========================================
+ Hits        10886    10958      +72     
+ Misses       7741     7678      -63
Flag Coverage Δ
#flutter_tool 58.8% <100%> (+0.35%) ⬆️
Impacted Files Coverage Δ
...s/flutter_tools/lib/src/windows/visual_studio.dart 81.81% <100%> (+2.4%) ⬆️
...lib/src/build_runner/web_compilation_delegate.dart 0% <0%> (-25.4%) ⬇️
packages/flutter_tools/lib/src/commands/run.dart 38.91% <0%> (-24.64%) ⬇️
packages/flutter_tools/lib/src/base/utils.dart 87.12% <0%> (-7.43%) ⬇️
packages/flutter_tools/lib/src/run_cold.dart 12.19% <0%> (-7.32%) ⬇️
...tter_tools/lib/src/build_system/targets/macos.dart 42.77% <0%> (-5.43%) ⬇️
packages/flutter_tools/lib/src/device.dart 57.64% <0%> (-4.12%) ⬇️
packages/flutter_tools/lib/src/version.dart 90.99% <0%> (-1.9%) ⬇️
packages/flutter_tools/lib/src/cache.dart 43.5% <0%> (-0.73%) ⬇️
packages/flutter_tools/lib/src/build_info.dart 74.86% <0%> (-0.55%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd84cea...b1499b3. Read the comment docs.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Thanks! Sorry for writing this technical debt into the implementation in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

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

The getters should never return null, so you can simplify these checks to just the isNotEmpty part.

Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: you could simplify the call sites using this by having it return an empty map instead of null; then they don't need to do null checks.

Copy link
Contributor

Choose a reason for hiding this comment

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

As above, you only need the second part.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add ", or {} if there is no such installation" to the end of the first sentence so the return contract is explicit up front.

The second part should be a new paragraph per Dart style.

Same for the other two *Details getters.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is essentially duplicating the note a few lines above; remove one or the other copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: I found this re-assignment construction (where the usable version variable is set to a value that might not actually be usable, then unset if needed) a bit hard to follow; I think a local variable for the lookup would make it clearer:

if (_cachedUsableVisualStudioDetails == null) {
  Map<String, dynamic> visualStudioWithComponentsDetails = [...];
  visualStudioWithComponentsDetails ??= [...];
  if (visualStudioWithComponentsDetails != null) {
    if (installationHasIssues(visualStudioWithComponentsDetails) {
      _cachedUsable... = visualStudioWithCompontesDetails;
    } else {
      _cachedAny... = visualStudioWithCompontesDetails;
    }
  }
  _cachedUsableVisualStudioDetails ??= <String, dynamic>{};
}
return _cachedUsableVisualStudioDetails;

Copy link
Contributor

Choose a reason for hiding this comment

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

Simplify.

@franciscojma86 franciscojma86 force-pushed the refactor branch 2 times, most recently from eec098d to f738cfe Compare September 12, 2019 16:43
@franciscojma86
Copy link
Contributor Author

This is good for review, PTAL!

@franciscojma86 franciscojma86 added t: flutter doctor Problem related to the "flutter doctor" tool platform-windows Building on or for Windows specifically labels Sep 12, 2019
Map<String, dynamic> _cachedUsableVisualStudioDetails;
Map<String, dynamic> get _usableVisualStudioDetails {
_cachedUsableVisualStudioDetails ??=
Map<String, dynamic> visualStudioDetails =
Copy link
Contributor

Choose a reason for hiding this comment

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

You're running this on every call, even if a result was already cached. This should all be inside an if-null check (I believe I had that in my suggested code in the other PR).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦‍♂ Added it as a check for != null and early return to avoid wrapping all the logic inside an if

@franciscojma86 franciscojma86 merged commit 576a455 into flutter:master Sep 12, 2019
@franciscojma86 franciscojma86 deleted the refactor branch September 12, 2019 22:48
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Sep 30, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-windows Building on or for Windows specifically t: flutter doctor Problem related to the "flutter doctor" tool tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants