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

Avoid running duplicate/ unnecessary auto restore #1198

Merged
merged 1 commit into from
Jun 28, 2017
Merged

Conversation

jainaashish
Copy link
Contributor

@jainaashish jainaashish commented Feb 22, 2017

This PR will delay auto restore when we're still expecting some nominations to come from project system and make sure to run a single auto restore for all the projects which will save performance as well as avoid unnecessary error/ warning messages from multiple auto restores.

Also, this will maximum delay auto restore for 20 secs, even after 20 secs we're missing some nominations then we'll continue with it and let it fail assuming there is something wrong with project system which is why they were not able to nominate. This is the fallback mechanism so that we never delay auto restore indefinitely.

And lastly, Solution restore requests are never delayed and processed immediately as soon as they arrive so that it doesn't change any behavior for explicit restore.

Fixes NuGet/Home#4307

@rrelyea @DoRonMotter @alpaix @emgarten

/// Returns number of nominations still pending for .net core projects.
/// </summary>
/// <returns>Number of pending nominations.</returns>
int GetExpectedProjectsNomination();
Copy link
Contributor

Choose a reason for hiding this comment

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

How about boolean IsAllProjectsNominated() instead? Actual count is not necessary and may be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm makes sense! earlier i was validating changes with previous run so used int.. but now it makes more sense to just use boolean.

{
// check if this .Net core project is nominated or not, and accordingly increase counter.
DependencyGraphSpec projectRestoreInfo;
if (_projectSystemCache.TryGetProjectRestoreInfo(cpsProject.MSBuildProjectPath, out projectRestoreInfo) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Noted in other places we tend to use GetNuGetProjectSafeName for polling the cache. What if project created and not saved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TryGetProjectRestoreInfo is only being used in CPSProjectReferenceProject and it always passes projectFullPath which is why I passed the same thing here to have the consistency.

// Drains the queue
while (!_pendingRequests.Value.IsCompleted
&& !token.IsCancellationRequested)
{
SolutionRestoreRequest discard;
if (!_pendingRequests.Value.TryTake(out discard, IdleTimeoutMs, token))
{
// check if there are pending nominations
currentExpectedNominations = _solutionManager.Value.GetExpectedProjectsNomination();
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider caching the result once all of the projects are nominated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thought so, but then there still could be cases where new projects are being created which are still missing nominations when it tries to run an auto restore which is why I didn't cache it. And also figuring out if projects are nominated or not, is a quick check so doesn't impact perf as well.

Copy link
Contributor

@alpaix alpaix left a comment

Choose a reason for hiding this comment

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

Address the feedback.

@mishra14
Copy link
Contributor

mishra14 commented Apr 6, 2017

@alpaix @emgarten : is this needed?

@jainaashish jainaashish force-pushed the asja-fix4307 branch 3 times, most recently from b80be5a to b2e846e Compare June 22, 2017 22:09
var netCoreProjects = GetNuGetProjects().OfType<NetCorePackageReferenceProject>().ToList();

// count for nominated projects so far
var nominatedProjects = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't have to count all of them, just find at least one without restore info.

// if we're still expecting some nominations and also haven't reached our max timeout
// then delay it for 1500 msec and try again.
retries++;
await Task.Delay(DelayAutoRestoreTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed. TryTake above will do wait just fine.

Copy link
Contributor

@alpaix alpaix left a comment

Choose a reason for hiding this comment

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

⌚️

@jainaashish
Copy link
Contributor Author

@alpaix As per our discussion, I've updated the PR

Copy link
Contributor

@alpaix alpaix left a comment

Choose a reason for hiding this comment

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

👏 Well done!

@jainaashish jainaashish merged commit 0267a34 into dev Jun 28, 2017
@jainaashish jainaashish deleted the asja-fix4307 branch June 28, 2017 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants