Skip to content
Snippets Groups Projects
Commit 5db22768 authored by Stanley Goldman's avatar Stanley Goldman
Browse files

Trying to get the PublishView to load faster

parent 3c43ec69
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,12 @@ namespace GitHub.Unity
callback(user);
}
public async Task GetCurrentUserAndOrganizations(Action<Octokit.User, IList<Organization>> callback)
{
Guard.ArgumentNotNull(callback, "callback");
await GetUsersAndOrganizationInternal(callback);
}
public async Task Login(string username, string password, Action<LoginResult> need2faCode, Action<bool, string> result)
{
Guard.ArgumentNotNull(need2faCode, "need2faCode");
......@@ -262,6 +268,23 @@ namespace GitHub.Unity
return userCache;
}
private async Task GetUsersAndOrganizationInternal(Action<Octokit.User, IList<Organization>> callback)
{
if (!await EnsureKeychainLoaded())
{
callback(null, null);
return;
}
var currentUserInternal = GetCurrentUserInternal();
var organizationInternal = GetOrganizationInternal();
currentUserInternal.Start(TaskScheduler.Current);
organizationInternal.Start(TaskScheduler.Current);
callback(await currentUserInternal,await organizationInternal);
}
private async Task<bool> EnsureKeychainLoaded()
{
logger.Trace("EnsureKeychainLoaded");
......
......@@ -17,5 +17,6 @@ namespace GitHub.Unity
Task<bool> ValidateCredentials();
Task Logout(UriString host);
Task GetCurrentUser(Action<Octokit.User> callback);
Task GetCurrentUserAndOrganizations(Action<Octokit.User, IList<Organization>> callback);
}
}
using System;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Rackspace.Threading;
using UnityEditor;
......@@ -67,34 +68,19 @@ namespace GitHub.Unity
isLoading = true;
Client.GetCurrentUser(user => {
Client.GetCurrentUserAndOrganizations((user, organizations) => {
if (user == null)
{
Logger.Warning("Unable to get current user");
return;
}
owners = new[] { user.Login };
username = user.Login;
Logger.Trace("GetOrganizations");
var organizationLogins = (organizations ?? Enumerable.Empty<Organization>())
.OrderBy(organization => organization.Login)
.Select(organization => organization.Login);
Client.GetOrganizations(organizations =>
{
if (organizations == null)
{
Logger.Warning("Unable to get list of organizations");
return;
}
Logger.Trace("Loaded {0} organizations", organizations.Count);
var organizationLogins = organizations
.OrderBy(organization => organization.Login)
.Select(organization => organization.Login);
owners = owners.Union(organizationLogins).ToArray();
});
owners = new[] { user.Login }.Union(organizationLogins).ToArray();
}).Finally(task => {
isLoading = false;
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment