Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 90473bf

Browse files
committed
Fix a delay in loading the connect page
Querying the registry for repositories is visibly delaying the UI, which is a no-no! Fixicate.
1 parent f856aa8 commit 90473bf

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

src/GitHub.Exports/Models/IConnectionManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.ObjectModel;
33
using System.Diagnostics.CodeAnalysis;
44
using GitHub.Primitives;
5-
using GitHub.Services;
5+
using System.Threading.Tasks;
66

77
namespace GitHub.Models
88
{
@@ -19,6 +19,6 @@ public interface IConnectionManager
1919
// for telling IRepositoryHosts that we need to login from cache
2020
[SuppressMessage("Microsoft.Design", "CA1009:DeclareEventHandlersCorrectly")]
2121
event Func<IConnection, IObservable<IConnection>> DoLogin;
22-
void RefreshRepositories();
22+
Task RefreshRepositories();
2323
}
2424
}

src/GitHub.Exports/Services/VSServices.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ static IEnumerable<ISimpleRepositoryModel> PokeTheRegistryForRepositoryList()
124124
if (path != null)
125125
return new SimpleRepositoryModel(path);
126126
}
127-
catch (Exception ex)
127+
// no sense spamming the log, the registry might have ton of stale things we don't care about
128+
catch (Exception)
128129
{
129-
VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error loading the repository from the registry '{0}'", ex));
130+
//VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "Error loading the repository from the registry '{0}'", ex));
130131
}
131132
return null;
132133
}

src/GitHub.VisualStudio/Services/ConnectionManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using GitHub.Models;
99
using GitHub.Services;
1010
using GitHub.Primitives;
11+
using System.Threading.Tasks;
1112

1213
namespace GitHub.VisualStudio
1314
{
@@ -126,9 +127,9 @@ public void RequestLogout(IConnection connection)
126127
Connections.Remove(connection);
127128
}
128129

129-
public void RefreshRepositories()
130+
public async Task RefreshRepositories()
130131
{
131-
var list = vsServices.GetKnownRepositories();
132+
var list = await Task.Run(() => vsServices.GetKnownRepositories());
132133
list.GroupBy(r => Connections.FirstOrDefault(c => r.CloneUrl != null && c.HostAddress.Equals(HostAddress.Create(r.CloneUrl))))
133134
.Where(g => g.Key != null)
134135
.ForEach(g =>

src/GitHub.VisualStudio/TeamExplorer/Connect/GitHubConnectSection.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Microsoft.VisualStudio;
1818
using NullGuard;
1919
using ReactiveUI;
20+
using System.Threading.Tasks;
2021

2122
namespace GitHub.VisualStudio.TeamExplorer.Connect
2223
{
@@ -148,7 +149,7 @@ protected void Refresh(IConnection connection)
148149
IsVisible = true;
149150
LoggedIn = true;
150151
if (ServiceProvider != null)
151-
RefreshRepositories();
152+
RefreshRepositories().Forget();
152153
}
153154
}
154155
}
@@ -271,9 +272,9 @@ void ShowNotification(ISimpleRepositoryModel newrepo, string msg)
271272
#endif
272273
}
273274

274-
void RefreshRepositories()
275+
async Task RefreshRepositories()
275276
{
276-
connectionManager.RefreshRepositories();
277+
await connectionManager.RefreshRepositories();
277278
RaisePropertyChanged("Repositories"); // trigger a re-check of the visibility of the listview based on item count
278279
}
279280

@@ -362,7 +363,7 @@ enum SectionState
362363
readonly Stateless.StateMachine<SectionState, string> machine;
363364
readonly ITeamExplorerSection section;
364365

365-
public SectionStateTracker(ITeamExplorerSection section, Action onRefreshed)
366+
public SectionStateTracker(ITeamExplorerSection section, Func<Task> onRefreshed)
366367
{
367368
this.section = section;
368369
machine = new Stateless.StateMachine<SectionState, string>(SectionState.Idle);
@@ -377,7 +378,7 @@ public SectionStateTracker(ITeamExplorerSection section, Action onRefreshed)
377378
.Ignore("Title")
378379
.PermitIf("IsBusy", SectionState.Idle, () => !this.section.IsBusy)
379380
.IgnoreIf("IsBusy", () => this.section.IsBusy)
380-
.OnExit(onRefreshed);
381+
.OnExit(() => onRefreshed());
381382

382383
section.PropertyChanged += TrackState;
383384
}

0 commit comments

Comments
 (0)