@@ -3,7 +3,7 @@ import type { Disposable } from './api/gitlens';
33import type { Container } from './container' ;
44import type { Account } from './git/models/author' ;
55import type { DefaultBranch } from './git/models/defaultBranch' ;
6- import type { IssueOrPullRequest } from './git/models/issue' ;
6+ import type { Issue , IssueOrPullRequest } from './git/models/issue' ;
77import type { PullRequest } from './git/models/pullRequest' ;
88import type { RepositoryMetadata } from './git/models/repositoryMetadata' ;
99import type { HostingIntegration , IntegrationBase , ResourceDescriptor } from './plus/integrations/integration' ;
@@ -12,6 +12,8 @@ import { isPromise } from './system/promise';
1212type Caches = {
1313 defaultBranch : { key : `repo:${string } `; value : DefaultBranch } ;
1414 // enrichedAutolinksBySha: { key: `sha:${string}:${string}`; value: Map<string, EnrichedAutolink> };
15+ issuesById : { key : `id:${string } :${string } `; value : Issue } ;
16+ issuesByIdAndResource : { key : `id:${string } :${string } :${string } `; value : Issue } ;
1517 issuesOrPrsById : { key : `id:${string } :${string } `; value : IssueOrPullRequest } ;
1618 issuesOrPrsByIdAndRepo : { key : `id:${string } :${string } :${string } `; value : IssueOrPullRequest } ;
1719 prByBranch : { key : `branch:${string } :${string } `; value : PullRequest } ;
@@ -127,6 +129,27 @@ export class CacheProvider implements Disposable {
127129 ) ;
128130 }
129131
132+ getIssue (
133+ id : string ,
134+ resource : ResourceDescriptor ,
135+ integration : IntegrationBase | undefined ,
136+ cacheable : Cacheable < Issue > ,
137+ options ?: { expiryOverride ?: boolean | number } ,
138+ ) : CacheResult < Issue > {
139+ const { key, etag } = getResourceKeyAndEtag ( resource , integration ) ;
140+
141+ if ( resource == null ) {
142+ return this . get ( 'issuesById' , `id:${ id } :${ key } ` , etag , cacheable , options ) ;
143+ }
144+ return this . get (
145+ 'issuesByIdAndResource' ,
146+ `id:${ id } :${ key } :${ JSON . stringify ( resource ) } }` ,
147+ etag ,
148+ cacheable ,
149+ options ,
150+ ) ;
151+ }
152+
130153 getPullRequest (
131154 id : string ,
132155 resource : ResourceDescriptor ,
@@ -259,6 +282,18 @@ function getExpiresAt<T extends Cache>(cache: T, value: CacheValue<T> | undefine
259282 case 'repoMetadata' :
260283 case 'currentAccount' :
261284 return 0 ; // Never expires
285+ case 'issuesById' :
286+ case 'issuesByIdAndResource' : {
287+ if ( value == null ) return 0 ; // Never expires
288+
289+ // Open issues expire after 1 hour, but closed issues expire after 12 hours unless recently updated and then expire in 1 hour
290+
291+ const issue = value as CacheValue < 'issuesById' > ;
292+ if ( ! issue . closed ) return defaultExpiresAt ;
293+
294+ const updatedAgo = now - ( issue . closedDate ?? issue . updatedDate ) . getTime ( ) ;
295+ return now + ( updatedAgo > 14 * 24 * 60 * 60 * 1000 ? 12 : 1 ) * 60 * 60 * 1000 ;
296+ }
262297 case 'issuesOrPrsById' :
263298 case 'issuesOrPrsByIdAndRepo' : {
264299 if ( value == null ) return 0 ; // Never expires
0 commit comments