Skip to content

Commit

Permalink
Fix hang in Solution Explorer search through transitive package items…
Browse files Browse the repository at this point in the history
… of dependencies tree (#5917)

* Revert "Reduce number of Dataflow updates through dependency tree code (#5508)"

This reverts commit d85c6ea.

Turns out that the search provider uses `GetLatestVersionAsync` on this
data source, meaning it must propagate a value for every input version.
I will fix the original issue in a different way, by updating the
consumer to ignore version-only changes instead.

* Avoid tree updates when the value is unchanged

This replaces the approach taken in #5508 in a way that doesn't interfere with Solution Explorer search.
  • Loading branch information
drewnoakes authored Jul 13, 2024
1 parent e5996d2 commit bca3348
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.Threading.Tasks.Dataflow;
Expand Down Expand Up @@ -39,7 +38,7 @@ protected override IDisposable LinkExternalInput(ITargetBlock<IProjectVersionedV

string? lastAssetsFilePath = null;
DateTime lastTimestampUtc = DateTime.MinValue;
AssetsFileDependenciesSnapshot? lastSnapshot = null;
AssetsFileDependenciesSnapshot lastSnapshot = AssetsFileDependenciesSnapshot.Empty;

var intermediateBlock =
new BufferBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>>(
Expand All @@ -49,7 +48,7 @@ IReceivableSourceBlock<IProjectVersionedValue<IProjectSubscriptionUpdate>> proje
= _activeConfiguredProjectSubscriptionService.ProjectRuleSource.SourceBlock;

IPropagatorBlock<IProjectVersionedValue<ValueTuple<IProjectSnapshot, IProjectSubscriptionUpdate>>, IProjectVersionedValue<AssetsFileDependenciesSnapshot>> transformBlock
= DataflowBlockSlim.CreateTransformManyBlock<IProjectVersionedValue<ValueTuple<IProjectSnapshot, IProjectSubscriptionUpdate>>, IProjectVersionedValue<AssetsFileDependenciesSnapshot>>(Transform, skipIntermediateInputData: true, skipIntermediateOutputData: true);
= DataflowBlockSlim.CreateTransformBlock<IProjectVersionedValue<ValueTuple<IProjectSnapshot, IProjectSubscriptionUpdate>>, IProjectVersionedValue<AssetsFileDependenciesSnapshot>>(Transform, skipIntermediateInputData: true, skipIntermediateOutputData: true);

return new DisposableBag
{
Expand All @@ -76,15 +75,15 @@ IPropagatorBlock<IProjectVersionedValue<ValueTuple<IProjectSnapshot, IProjectSub
PropagateCompletion = true // Make sure source block completion and faults flow onto the target block to avoid hangs.
};

IEnumerable<IProjectVersionedValue<AssetsFileDependenciesSnapshot>> Transform(IProjectVersionedValue<ValueTuple<IProjectSnapshot, IProjectSubscriptionUpdate>> update)
IProjectVersionedValue<AssetsFileDependenciesSnapshot> Transform(IProjectVersionedValue<ValueTuple<IProjectSnapshot, IProjectSubscriptionUpdate>> update)
{
var projectSnapshot = (IProjectSnapshot2)update.Value.Item1;
IProjectSubscriptionUpdate subscriptionUpdate = update.Value.Item2;

string? path = null;
DateTime timestampUtc = DateTime.MinValue;

AssetsFileDependenciesSnapshot? snapshot = lastSnapshot;
AssetsFileDependenciesSnapshot snapshot = lastSnapshot;

if (subscriptionUpdate.CurrentState.TryGetValue(ConfigurationGeneralRule.SchemaName, out IProjectRuleSnapshot ruleSnapshot))
{
Expand Down Expand Up @@ -116,21 +115,13 @@ IEnumerable<IProjectVersionedValue<AssetsFileDependenciesSnapshot>> Transform(IP
lastAssetsFilePath = path;
lastTimestampUtc = timestampUtc;

snapshot ??= AssetsFileDependenciesSnapshot.Empty;

lastSnapshot = snapshot = snapshot.UpdateFromAssetsFile(path);

yield return new ProjectVersionedValue<AssetsFileDependenciesSnapshot>(snapshot, update.DataSourceVersions);
lastSnapshot = snapshot = lastSnapshot.UpdateFromAssetsFile(path);
}
}
}
}

if (lastSnapshot is null)
{
lastSnapshot = AssetsFileDependenciesSnapshot.Empty;
yield return new ProjectVersionedValue<AssetsFileDependenciesSnapshot>(lastSnapshot, update.DataSourceVersions);
}
return new ProjectVersionedValue<AssetsFileDependenciesSnapshot>(snapshot, update.DataSourceVersions);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,21 @@ protected override bool TryCreateCollectionSource(

var collectionSource = new AggregateRelationCollectionSource(hierarchyItem);
AggregateContainsRelationCollection? collection = null;
AssetsFileDependenciesSnapshot? lastSnapshot = null;

var actionBlock = new ActionBlock<IProjectVersionedValue<AssetsFileDependenciesSnapshot>>(
async versionedValue =>
{
AssetsFileDependenciesSnapshot snapshot = versionedValue.Value;

if (ReferenceEquals(snapshot, lastSnapshot))
{
// Skip version-only updates.
return;
}

lastSnapshot = snapshot;

if (snapshot.TryGetTarget(target, out AssetsFileTarget? targetData))
{
if (TryGetLibrary(targetData, libraryName, out AssetsFileTargetLibrary? library))
Expand Down

0 comments on commit bca3348

Please sign in to comment.