@@ -15,6 +15,7 @@ type Caches = {
1515 issuesOrPrsById : { key : `id:${string } :${string } `; value : IssueOrPullRequest } ;
1616 issuesOrPrsByIdAndRepo : { key : `id:${string } :${string } :${string } `; value : IssueOrPullRequest } ;
1717 prByBranch : { key : `branch:${string } :${string } `; value : PullRequest } ;
18+ prsById : { key : `id:${string } :${string } `; value : PullRequest } ;
1819 prsBySha : { key : `sha:${string } :${string } `; value : PullRequest } ;
1920 repoMetadata : { key : `repo:${string } `; value : RepositoryMetadata } ;
2021 currentAccount : { key : `id:${string } `; value : Account } ;
@@ -86,6 +87,25 @@ export class CacheProvider implements Disposable {
8687 return item . value as CacheResult < CacheValue < T > > ;
8788 }
8889
90+ getCurrentAccount (
91+ integration : IntegrationBase ,
92+ cacheable : Cacheable < Account > ,
93+ options ?: { expiryOverride ?: boolean | number } ,
94+ ) : CacheResult < Account > {
95+ const { key, etag } = getIntegrationKeyAndEtag ( integration ) ;
96+ return this . get ( 'currentAccount' , `id:${ key } ` , etag , cacheable , options ) ;
97+ }
98+
99+ // getEnrichedAutolinks(
100+ // sha: string,
101+ // remoteOrProvider: Integration,
102+ // cacheable: Cacheable<Map<string, EnrichedAutolink>>,
103+ // options?: { force?: boolean },
104+ // ): CacheResult<Map<string, EnrichedAutolink>> {
105+ // const { key, etag } = getRemoteKeyAndEtag(remoteOrProvider);
106+ // return this.get('enrichedAutolinksBySha', `sha:${sha}:${key}`, etag, cacheable, options);
107+ // }
108+
89109 getIssueOrPullRequest (
90110 id : string ,
91111 resource : ResourceDescriptor ,
@@ -107,15 +127,20 @@ export class CacheProvider implements Disposable {
107127 ) ;
108128 }
109129
110- // getEnrichedAutolinks(
111- // sha: string,
112- // remoteOrProvider: Integration,
113- // cacheable: Cacheable<Map<string, EnrichedAutolink>>,
114- // options?: { force?: boolean },
115- // ): CacheResult<Map<string, EnrichedAutolink>> {
116- // const { key, etag } = getRemoteKeyAndEtag(remoteOrProvider);
117- // return this.get('enrichedAutolinksBySha', `sha:${sha}:${key}`, etag, cacheable, options);
118- // }
130+ getPullRequest (
131+ id : string ,
132+ resource : ResourceDescriptor ,
133+ integration : IntegrationBase | undefined ,
134+ cacheable : Cacheable < PullRequest > ,
135+ options ?: { expiryOverride ?: boolean | number } ,
136+ ) : CacheResult < PullRequest > {
137+ const { key, etag } = getResourceKeyAndEtag ( resource , integration ) ;
138+
139+ if ( resource == null ) {
140+ return this . get ( 'prsById' , `id:${ id } :${ key } ` , etag , cacheable , options ) ;
141+ }
142+ return this . get ( 'prsById' , `id:${ id } :${ key } :${ JSON . stringify ( resource ) } }` , etag , cacheable , options ) ;
143+ }
119144
120145 getPullRequestForBranch (
121146 branch : string ,
@@ -124,11 +149,10 @@ export class CacheProvider implements Disposable {
124149 cacheable : Cacheable < PullRequest > ,
125150 options ?: { expiryOverride ?: boolean | number } ,
126151 ) : CacheResult < PullRequest > {
127- const cache = 'prByBranch' ;
128152 const { key, etag } = getResourceKeyAndEtag ( repo , integration ) ;
129153 // Wrap the cacheable so we can also add the result to the issuesOrPrsById cache
130154 return this . get (
131- cache ,
155+ 'prByBranch' ,
132156 `branch:${ branch } :${ key } ` ,
133157 etag ,
134158 this . wrapPullRequestCacheable ( cacheable , key , etag ) ,
@@ -143,10 +167,15 @@ export class CacheProvider implements Disposable {
143167 cacheable : Cacheable < PullRequest > ,
144168 options ?: { expiryOverride ?: boolean | number } ,
145169 ) : CacheResult < PullRequest > {
146- const cache = 'prsBySha' ;
147170 const { key, etag } = getResourceKeyAndEtag ( repo , integration ) ;
148171 // Wrap the cacheable so we can also add the result to the issuesOrPrsById cache
149- return this . get ( cache , `sha:${ sha } :${ key } ` , etag , this . wrapPullRequestCacheable ( cacheable , key , etag ) , options ) ;
172+ return this . get (
173+ 'prsBySha' ,
174+ `sha:${ sha } :${ key } ` ,
175+ etag ,
176+ this . wrapPullRequestCacheable ( cacheable , key , etag ) ,
177+ options ,
178+ ) ;
150179 }
151180
152181 getRepositoryDefaultBranch (
@@ -169,15 +198,6 @@ export class CacheProvider implements Disposable {
169198 return this . get ( 'repoMetadata' , `repo:${ key } ` , etag , cacheable , options ) ;
170199 }
171200
172- getCurrentAccount (
173- integration : IntegrationBase ,
174- cacheable : Cacheable < Account > ,
175- options ?: { expiryOverride ?: boolean | number } ,
176- ) : CacheResult < Account > {
177- const { key, etag } = getIntegrationKeyAndEtag ( integration ) ;
178- return this . get ( 'currentAccount' , `id:${ key } ` , etag , cacheable , options ) ;
179- }
180-
181201 private set < T extends Cache > (
182202 cache : T ,
183203 key : CacheKey < T > ,
@@ -252,12 +272,13 @@ function getExpiresAt<T extends Cache>(cache: T, value: CacheValue<T> | undefine
252272 return now + ( updatedAgo > 14 * 24 * 60 * 60 * 1000 ? 12 : 1 ) * 60 * 60 * 1000 ;
253273 }
254274 case 'prByBranch' :
275+ case 'prsById' :
255276 case 'prsBySha' : {
256277 if ( value == null ) return cache === 'prByBranch' ? defaultExpiresAt : 0 /* Never expires */ ;
257278
258279 // Open prs expire after 1 hour, but closed/merge prs expire after 12 hours unless recently updated and then expire in 1 hour
259280
260- const pr = value as CacheValue < 'prsBySha ' | 'prByBranch ' > ;
281+ const pr = value as CacheValue < 'prByBranch ' | 'prsById' | 'prsBySha '> ;
261282 if ( pr . state === 'opened' ) return defaultExpiresAt ;
262283
263284 const updatedAgo = now - ( pr . closedDate ?? pr . mergedDate ?? pr . updatedDate ) . getTime ( ) ;
0 commit comments