From a286988433d08986169c69ecbfbe7ace63ed2669 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Wed, 20 Dec 2023 18:07:35 +0000 Subject: [PATCH 1/3] unblock main thread when fetching user votes - before fetching user votes could potentially slow down dynamo loading as it was being executed on the main thread - now using Task.Run to execute on a separate thread and unblock the loading process --- .../PackageManager/PackageManagerClientViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs index 7ac62388b67..417e72525ba 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs @@ -260,7 +260,7 @@ public string Username public ICommand ToggleLoginStateCommand { get; private set; } /// - /// Contains all votes the user has been submitted. + /// Contains all votes the user has submitted. /// Will allow the user to vote for a package they have not upvoted before /// private List Uservotes { get; set; } @@ -285,7 +285,7 @@ internal PackageManagerClientViewModel(DynamoViewModel dynamoViewModel, PackageM if (AuthenticationManager.LoginState.Equals(LoginState.LoggedIn)) { - this.Uservotes = this.Model.UserVotes(); + Task.Run(() => this.Uservotes = this.Model.UserVotes()); } } From e82293395e57ebce3d6afead3c6522f989116cb6 Mon Sep 17 00:00:00 2001 From: Deyan Nenov Date: Fri, 12 Jan 2024 19:42:20 +0000 Subject: [PATCH 2/3] moved uservotes call closer to execution --- .../PackageManager/PackageManagerClientViewModel.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs index d7fe9a09895..d6935ae0af8 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs @@ -273,11 +273,6 @@ internal PackageManagerClientViewModel(DynamoViewModel dynamoViewModel, PackageM RaisePropertyChanged("Username"); }; } - - if (AuthenticationManager.LoginState.Equals(LoginState.LoggedIn) && !dynamoViewModel.Model.NoNetworkMode) - { - Task.Run(() => this.Uservotes = this.Model.UserVotes()); - } } private void ToggleLoginState() @@ -482,6 +477,12 @@ public List ListAll() { CachedPackageList = new List(); + // Attempt to load user votes prior to using it + if (AuthenticationManager.LoginState.Equals(LoginState.LoggedIn) && Uservotes == null) + { + Task.Run(() => this.Uservotes = this.Model.UserVotes()); + } + foreach (var header in Model.ListAll()) { var ele = new PackageManagerSearchElement(header); From 63d880a42d7616b71fb73f1927a367c2d76b8f16 Mon Sep 17 00:00:00 2001 From: pinzart90 Date: Wed, 7 Feb 2024 09:36:18 -0500 Subject: [PATCH 3/3] Update PackageManagerClientViewModel.cs --- .../PackageManager/PackageManagerClientViewModel.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs index d6935ae0af8..8ed18623df7 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs @@ -477,12 +477,8 @@ public List ListAll() { CachedPackageList = new List(); - // Attempt to load user votes prior to using it - if (AuthenticationManager.LoginState.Equals(LoginState.LoggedIn) && Uservotes == null) - { - Task.Run(() => this.Uservotes = this.Model.UserVotes()); - } - + // Calls to Model.UserVotes and Model.ListAll might take a long time to run (so do not use them syncronously in the UI thread) + Uservotes = this.Model.UserVotes(); foreach (var header in Model.ListAll()) { var ele = new PackageManagerSearchElement(header);