-
Notifications
You must be signed in to change notification settings - Fork 675
DYN-8564: run autocomplete search in background thread #16265
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| using System.IO; | ||
| using System.Linq; | ||
| using System.Text.RegularExpressions; | ||
| using System.Threading.Tasks; | ||
| using Dynamo.Configuration; | ||
| using Dynamo.Engine; | ||
| using Dynamo.Graph.Connectors; | ||
|
|
@@ -47,6 +48,23 @@ public class NodeAutoCompleteSearchViewModel : SearchViewModel | |
| private const string nodeClusterAutocompleteMLEndpoint = "MLNodeClusterAutocomplete"; | ||
| internal bool IsOpen { get; set; } | ||
|
|
||
| private bool resultsLoaded; | ||
|
|
||
| /// <summary> | ||
| /// Flag that indicates whether results are loading (false) or they have loaded (true). | ||
| /// This is set as true for both succesfully and unsuccessfully loading the results. | ||
| /// </summary> | ||
| [Obsolete("This method will be removed in a future version of Dynamo")] | ||
| public bool ResultsLoaded | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we need this to be public due to the binding. Let's add a comment an d also make it obsolete. |
||
| { | ||
| get { return resultsLoaded; } | ||
| set | ||
| { | ||
| resultsLoaded = value; | ||
| RaisePropertyChanged(nameof(ResultsLoaded)); | ||
| } | ||
| } | ||
|
|
||
| // Lucene search utility to perform indexing operations just for NodeAutocomplete. | ||
| internal LuceneSearchUtility LuceneUtility | ||
| { | ||
|
|
@@ -161,6 +179,7 @@ public bool DisplayLowConfidence | |
| } | ||
|
|
||
| internal event Action<NodeModel> ParentNodeRemoved; | ||
| private Guid LastRequestGuid; | ||
|
|
||
| /// <summary> | ||
| /// Constructor | ||
|
|
@@ -290,27 +309,55 @@ internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete() | |
|
|
||
| internal void ShowNodeAutocompleMLResults() | ||
| { | ||
| //this should run on the UI thread, so thread safety is not a concern | ||
| LastRequestGuid = Guid.NewGuid(); | ||
| var myRequest = LastRequestGuid; | ||
|
|
||
| MLNodeAutoCompletionResponse MLresults = null; | ||
|
|
||
| var request = GenerateRequestForMLAutocomplete(); | ||
|
|
||
| string jsonRequest = JsonConvert.SerializeObject(request); | ||
|
|
||
| // Get results from the ML API. | ||
| try | ||
| ResultsLoaded = false; | ||
|
chubakueno marked this conversation as resolved.
|
||
| Task.Run(() => | ||
| { | ||
| MLresults = GetMLNodeAutocompleteResults(jsonRequest); | ||
| try | ||
| { | ||
| MLresults = GetMLNodeAutocompleteResults(jsonRequest); | ||
| this.dynamoViewModel.UIDispatcher.BeginInvoke(() => UpdateUIWithRresults(MLresults, myRequest)); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| this.dynamoViewModel.UIDispatcher.BeginInvoke(() => | ||
| { | ||
| ResultsLoaded = true; //fail gracefully | ||
| dynamoViewModel.Model.Logger.Log("Unable to fetch ML Node autocomplete results: " + ex.Message); | ||
| DisplayAutocompleteMLStaticPage = true; | ||
| AutocompleteMLTitle = Resources.LoginNeededTitle; | ||
| AutocompleteMLMessage = Resources.LoginNeededMessage; | ||
| Analytics.TrackEvent(Actions.View, Categories.NodeAutoCompleteOperations, "UnabletoFetch"); | ||
| return; | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| private void UpdateUIWithRresults(MLNodeAutoCompletionResponse MLresults, Guid myRequest) | ||
| { | ||
| if (LastRequestGuid != myRequest) | ||
| { | ||
| //a newer request came, we're no longer interested in the results of this one | ||
| //only latest request has the right to be committed to the UI and internal data structures | ||
| return; | ||
| } | ||
| catch (Exception ex) | ||
| if (!IsOpen) | ||
| { | ||
| dynamoViewModel.Model.Logger.Log("Unable to fetch ML Node autocomplete results: " + ex.Message); | ||
| DisplayAutocompleteMLStaticPage = true; | ||
| AutocompleteMLTitle = Resources.LoginNeededTitle; | ||
| AutocompleteMLMessage = Resources.LoginNeededMessage; | ||
| Analytics.TrackEvent(Actions.View, Categories.NodeAutoCompleteOperations, "UnabletoFetch"); | ||
| // view disappeared while the background thread was waiting for the server response. | ||
| // Ignore the results as we're no longer interested. | ||
| return; | ||
| } | ||
|
|
||
| ResultsLoaded = true; | ||
| // no results | ||
| if (MLresults == null || MLresults.Results.Count() == 0) | ||
| { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.