Skip to content

Commit

Permalink
DYN-6769 Improving Dynamo Load Graph II - 2
Browse files Browse the repository at this point in the history
Instead of using a static Dictionary now I will be using a normal instance that will be initialized in DynamoViewModel and pass it to NodeAutoCompleteSearchViewModel, in this case we are also confirming that only be executed once.
  • Loading branch information
RobertGlobant20 committed Apr 17, 2024
1 parent e3fa5b3 commit 5f255b1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
25 changes: 24 additions & 1 deletion src/DynamoCoreWpf/ViewModels/Core/DynamoViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public partial class DynamoViewModel : ViewModelBase, IDynamoViewModel

internal DynamoMLDataPipelineExtension MLDataPipelineExtension { get; set; }

internal static Dictionary<string, NodeSearchElementViewModel> DefaultAutocompleteCandidates = new Dictionary<string, NodeSearchElementViewModel>();
internal Dictionary<string, NodeSearchElementViewModel> DefaultAutocompleteCandidates;

/// <summary>
/// Collection of Right SideBar tab items: view extensions and docked windows.
Expand Down Expand Up @@ -697,6 +697,28 @@ public struct StartConfiguration
return new DynamoViewModel(startConfiguration);
}

private void SearchDefaultNodeAutocompleteCandidates()
{
var tempSearchViewModel = new SearchViewModel(this)
{
Visible = true
};
DefaultAutocompleteCandidates = new Dictionary<string, NodeSearchElementViewModel>();

// TODO: These are basic input types in Dynamo
// This should be only served as a temporary default case.
var queries = new List<string>() { "String", "Number Slider", "Integer Slider", "Number", "Boolean", "Watch", "Watch 3D", "Python Script" };
foreach (var query in queries)
{
var foundNode = tempSearchViewModel.Search(query).Where(n => n.Name.Equals(query)).FirstOrDefault();
if (foundNode != null)
{
DefaultAutocompleteCandidates.Add(foundNode.Name, foundNode);
}
}
tempSearchViewModel.Dispose();
}

protected DynamoViewModel(StartConfiguration startConfiguration)
{
// CurrentDomain_UnhandledException - catches unhandled exceptions that are fatal to the current process. These exceptions cannot be handled and process termination is guaranteed
Expand Down Expand Up @@ -736,6 +758,7 @@ protected DynamoViewModel(StartConfiguration startConfiguration)

//add the initial workspace and register for future
//updates to the workspaces collection
SearchDefaultNodeAutocompleteCandidates();
var homespaceViewModel = new HomeWorkspaceViewModel(model.CurrentWorkspace as HomeWorkspaceModel, this);
workspaces.Add(homespaceViewModel);
currentWorkspaceViewModel = homespaceViewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public bool DisplayLowConfidence
internal NodeAutoCompleteSearchViewModel(DynamoViewModel dynamoViewModel) : base(dynamoViewModel)
{
// Off load some time consuming operation here
InitializeDefaultAutoCompleteCandidates();
DefaultResults = dynamoViewModel.DefaultAutocompleteCandidates.Values;
ServiceVersion = string.Empty;
}

Expand All @@ -179,32 +179,6 @@ internal void ResetAutoCompleteSearchViewState()
searchElementsCache = new List<NodeSearchElementViewModel>();
}

private void InitializeDefaultAutoCompleteCandidates()
{
var candidates = new List<NodeSearchElementViewModel>();
// TODO: These are basic input types in Dynamo
// This should be only served as a temporary default case.
var queries = new List<string>(){"String", "Number Slider", "Integer Slider", "Number", "Boolean", "Watch", "Watch 3D", "Python Script"};
var nodeNamesList = DynamoViewModel.DefaultAutocompleteCandidates.Keys.ToList();
if (nodeNamesList.Where(queries.Contains).Any() == true)
{
DefaultResults = DynamoViewModel.DefaultAutocompleteCandidates.Values;
}
else
{
foreach (var query in queries)
{
var foundNode = Search(query).Where(n => n.Name.Equals(query)).FirstOrDefault();
if (foundNode != null)
{
candidates.Add(foundNode);
DynamoViewModel.DefaultAutocompleteCandidates.Add(foundNode.Name, foundNode);
}
}
DefaultResults = candidates;
}
}

internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete()
{
// Initialize request for the the ML API
Expand Down

0 comments on commit 5f255b1

Please sign in to comment.