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

Commit c996266

Browse files
committed
Enable the cache for PRs in ModelService.
1 parent e5aecc9 commit c996266

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/GitHub.App/Services/ModelService.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace GitHub.Services
2323
[PartCreationPolicy(CreationPolicy.NonShared)]
2424
public class ModelService : IModelService
2525
{
26+
public const string PRPrefix = "pr";
2627
static readonly Logger log = LogManager.GetCurrentClassLogger();
2728

2829
readonly IApiClient apiClient;
@@ -184,12 +185,14 @@ public IObservable<IPullRequestModel> GetPullRequest(ILocalRepositoryModel repo,
184185

185186
return Observable.Defer(() =>
186187
{
187-
// TODO: This needs to go via the cache.
188-
return Observable.CombineLatest(
189-
apiClient.GetPullRequest(repo.CloneUrl.Owner, repo.CloneUrl.RepositoryName, number),
190-
apiClient.GetPullRequestFiles(repo.CloneUrl.Owner, repo.CloneUrl.RepositoryName, number).ToList(),
191-
(pr, files) => new { PullRequest = pr, Files = files })
192-
.Select(x => PullRequestCacheItem.Create(x.PullRequest, x.Files))
188+
return hostCache.GetAndRefreshObject(PRPrefix + '|' + number, () =>
189+
Observable.CombineLatest(
190+
apiClient.GetPullRequest(repo.CloneUrl.Owner, repo.CloneUrl.RepositoryName, number),
191+
apiClient.GetPullRequestFiles(repo.CloneUrl.Owner, repo.CloneUrl.RepositoryName, number).ToList(),
192+
(pr, files) => new { PullRequest = pr, Files = files })
193+
.Select(x => PullRequestCacheItem.Create(x.PullRequest, x.Files)),
194+
TimeSpan.Zero,
195+
TimeSpan.FromDays(7))
193196
.Select(Create);
194197
});
195198
}
@@ -364,13 +367,13 @@ IPullRequestModel Create(PullRequestCacheItem prCacheItem)
364367
prCacheItem.UpdatedAt)
365368
{
366369
Assignee = prCacheItem.Assignee != null ? Create(prCacheItem.Assignee) : null,
367-
Base = prCacheItem.Base,
368-
Body = prCacheItem.Body,
370+
Base = prCacheItem.Base ?? new GitReferenceModel(),
371+
Body = prCacheItem.Body ?? string.Empty,
369372
ChangedFiles = prCacheItem.ChangedFiles.Select(x => (IPullRequestFileModel)new PullRequestFileModel(x.FileName, x.Status)).ToList(),
370373
CommentCount = prCacheItem.CommentCount,
371374
CommitCount = prCacheItem.CommitCount,
372375
CreatedAt = prCacheItem.CreatedAt,
373-
Head = prCacheItem.Head,
376+
Head = prCacheItem.Head ?? new GitReferenceModel(),
374377
State = prCacheItem.State.HasValue ?
375378
prCacheItem.State.Value :
376379
prCacheItem.IsOpen.Value ? PullRequestStateEnum.Open : PullRequestStateEnum.Closed,

0 commit comments

Comments
 (0)