Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 5db2276

Browse files
Trying to get the PublishView to load faster
1 parent 3c43ec6 commit 5db2276

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

src/GitHub.Api/Application/ApiClient.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public async Task GetCurrentUser(Action<Octokit.User> callback)
7878
callback(user);
7979
}
8080

81+
public async Task GetCurrentUserAndOrganizations(Action<Octokit.User, IList<Organization>> callback)
82+
{
83+
Guard.ArgumentNotNull(callback, "callback");
84+
await GetUsersAndOrganizationInternal(callback);
85+
}
86+
8187
public async Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result)
8288
{
8389
Guard.ArgumentNotNull(need2faCode, "need2faCode");
@@ -262,6 +268,23 @@ private async Task<IList<Organization>> GetOrganizationInternal()
262268
return userCache;
263269
}
264270

271+
private async Task GetUsersAndOrganizationInternal(Action<Octokit.User, IList<Organization>> callback)
272+
{
273+
if (!await EnsureKeychainLoaded())
274+
{
275+
callback(null, null);
276+
return;
277+
}
278+
279+
var currentUserInternal = GetCurrentUserInternal();
280+
var organizationInternal = GetOrganizationInternal();
281+
282+
currentUserInternal.Start(TaskScheduler.Current);
283+
organizationInternal.Start(TaskScheduler.Current);
284+
285+
callback(await currentUserInternal,await organizationInternal);
286+
}
287+
265288
private async Task<bool> EnsureKeychainLoaded()
266289
{
267290
logger.Trace("EnsureKeychainLoaded");

src/GitHub.Api/Application/IApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ interface IApiClient
1717
Task<bool> ValidateCredentials();
1818
Task Logout(UriString host);
1919
Task GetCurrentUser(Action<Octokit.User> callback);
20+
Task GetCurrentUserAndOrganizations(Action<Octokit.User, IList<Organization>> callback);
2021
}
2122
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/PUblishView.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Linq;
3+
using System.Threading.Tasks;
34
using Octokit;
45
using Rackspace.Threading;
56
using UnityEditor;
@@ -67,34 +68,19 @@ private void PopulateView()
6768

6869
isLoading = true;
6970

70-
Client.GetCurrentUser(user => {
71+
Client.GetCurrentUserAndOrganizations((user, organizations) => {
7172
if (user == null)
7273
{
73-
Logger.Warning("Unable to get current user");
7474
return;
7575
}
7676

77-
owners = new[] { user.Login };
7877
username = user.Login;
7978

80-
Logger.Trace("GetOrganizations");
79+
var organizationLogins = (organizations ?? Enumerable.Empty<Organization>())
80+
.OrderBy(organization => organization.Login)
81+
.Select(organization => organization.Login);
8182

82-
Client.GetOrganizations(organizations =>
83-
{
84-
if (organizations == null)
85-
{
86-
Logger.Warning("Unable to get list of organizations");
87-
return;
88-
}
89-
90-
Logger.Trace("Loaded {0} organizations", organizations.Count);
91-
92-
var organizationLogins = organizations
93-
.OrderBy(organization => organization.Login)
94-
.Select(organization => organization.Login);
95-
96-
owners = owners.Union(organizationLogins).ToArray();
97-
});
83+
owners = new[] { user.Login }.Union(organizationLogins).ToArray();
9884
}).Finally(task => {
9985
isLoading = false;
10086
});

0 commit comments

Comments
 (0)