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

Commit

Permalink
Merge fixes/repository-list into release/1.0.16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shana committed Dec 18, 2015
2 parents 1e7be3d + cac1da8 commit 81638d1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/GitHub.App/Services/ModelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ IObservable<IEnumerable<AccountCacheItem>> GetUser()
{
return hostCache.GetAndRefreshObject("user",
() => apiClient.GetUser().Select(AccountCacheItem.Create), TimeSpan.FromMinutes(5), TimeSpan.FromDays(7))
.Take(1)
.PublishLast()
.RefCount()
.ToList();
}

Expand All @@ -107,7 +108,7 @@ IObservable<IEnumerable<AccountCacheItem>> GetUserOrganizations()
return GetUserFromCache().SelectMany(user =>
hostCache.GetAndRefreshObject(user.Login + "|orgs",
() => apiClient.GetOrganizations().Select(AccountCacheItem.Create).ToList(),
TimeSpan.FromMinutes(5), TimeSpan.FromDays(7)))
TimeSpan.FromMinutes(2), TimeSpan.FromDays(7)))
.Catch<IEnumerable<AccountCacheItem>, KeyNotFoundException>(
// This could in theory happen if we try to call this before the user is logged in.
e =>
Expand All @@ -125,8 +126,12 @@ IObservable<IEnumerable<AccountCacheItem>> GetUserOrganizations()
public IObservable<IReadOnlyList<IRepositoryModel>> GetRepositories()
{
return GetUserRepositories(RepositoryType.Owner)
.Take(1)
.Concat(GetUserRepositories(RepositoryType.Member).Take(1))
.PublishLast()
.RefCount()
.Concat(GetUserRepositories(RepositoryType.Member)
.PublishLast()
.RefCount()
)
.Concat(GetAllRepositoriesForAllOrganizations());
}

Expand Down Expand Up @@ -174,7 +179,7 @@ IObservable<IReadOnlyList<IRepositoryModel>> GetUserRepositories(RepositoryType
return Observable.Defer(() => GetUserFromCache().SelectMany(user =>
hostCache.GetAndRefreshObject(string.Format(CultureInfo.InvariantCulture, "{0}|{1}:repos", user.Login, repositoryType),
() => GetUserRepositoriesFromApi(repositoryType),
TimeSpan.FromMinutes(5),
TimeSpan.FromMinutes(2),
TimeSpan.FromDays(7)))
.ToReadOnlyList(Create))
.Catch<IReadOnlyList<IRepositoryModel>, KeyNotFoundException>(
Expand Down Expand Up @@ -202,7 +207,10 @@ IObservable<IReadOnlyList<IRepositoryModel>> GetAllRepositoriesForAllOrganizatio
{
return GetUserOrganizations()
.SelectMany(org => org.ToObservable())
.SelectMany(org => GetOrganizationRepositories(org.Login).Take(1));
.SelectMany(org => GetOrganizationRepositories(org.Login)
.PublishLast()
.RefCount()
);
}

IObservable<IReadOnlyList<IRepositoryModel>> GetOrganizationRepositories(string organization)
Expand All @@ -211,7 +219,7 @@ IObservable<IReadOnlyList<IRepositoryModel>> GetOrganizationRepositories(string
hostCache.GetAndRefreshObject(string.Format(CultureInfo.InvariantCulture, "{0}|{1}|repos", user.Login, organization),
() => apiClient.GetRepositoriesForOrganization(organization).Select(
RepositoryCacheItem.Create).ToList(),
TimeSpan.FromMinutes(5),
TimeSpan.FromMinutes(2),
TimeSpan.FromDays(7)))
.ToReadOnlyList(Create))
.Catch<IReadOnlyList<IRepositoryModel>, KeyNotFoundException>(
Expand Down

0 comments on commit 81638d1

Please sign in to comment.