@@ -15,6 +15,7 @@ type Caches = {
15
15
issuesOrPrsById : { key : `id:${string } :${string } `; value : IssueOrPullRequest } ;
16
16
issuesOrPrsByIdAndRepo : { key : `id:${string } :${string } :${string } `; value : IssueOrPullRequest } ;
17
17
prByBranch : { key : `branch:${string } :${string } `; value : PullRequest } ;
18
+ prsById : { key : `id:${string } :${string } `; value : PullRequest } ;
18
19
prsBySha : { key : `sha:${string } :${string } `; value : PullRequest } ;
19
20
repoMetadata : { key : `repo:${string } `; value : RepositoryMetadata } ;
20
21
currentAccount : { key : `id:${string } `; value : Account } ;
@@ -86,6 +87,25 @@ export class CacheProvider implements Disposable {
86
87
return item . value as CacheResult < CacheValue < T > > ;
87
88
}
88
89
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
+
89
109
getIssueOrPullRequest (
90
110
id : string ,
91
111
resource : ResourceDescriptor ,
@@ -107,15 +127,20 @@ export class CacheProvider implements Disposable {
107
127
) ;
108
128
}
109
129
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
+ }
119
144
120
145
getPullRequestForBranch (
121
146
branch : string ,
@@ -124,11 +149,10 @@ export class CacheProvider implements Disposable {
124
149
cacheable : Cacheable < PullRequest > ,
125
150
options ?: { expiryOverride ?: boolean | number } ,
126
151
) : CacheResult < PullRequest > {
127
- const cache = 'prByBranch' ;
128
152
const { key, etag } = getResourceKeyAndEtag ( repo , integration ) ;
129
153
// Wrap the cacheable so we can also add the result to the issuesOrPrsById cache
130
154
return this . get (
131
- cache ,
155
+ 'prByBranch' ,
132
156
`branch:${ branch } :${ key } ` ,
133
157
etag ,
134
158
this . wrapPullRequestCacheable ( cacheable , key , etag ) ,
@@ -143,10 +167,15 @@ export class CacheProvider implements Disposable {
143
167
cacheable : Cacheable < PullRequest > ,
144
168
options ?: { expiryOverride ?: boolean | number } ,
145
169
) : CacheResult < PullRequest > {
146
- const cache = 'prsBySha' ;
147
170
const { key, etag } = getResourceKeyAndEtag ( repo , integration ) ;
148
171
// 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
+ ) ;
150
179
}
151
180
152
181
getRepositoryDefaultBranch (
@@ -169,15 +198,6 @@ export class CacheProvider implements Disposable {
169
198
return this . get ( 'repoMetadata' , `repo:${ key } ` , etag , cacheable , options ) ;
170
199
}
171
200
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
-
181
201
private set < T extends Cache > (
182
202
cache : T ,
183
203
key : CacheKey < T > ,
@@ -252,12 +272,13 @@ function getExpiresAt<T extends Cache>(cache: T, value: CacheValue<T> | undefine
252
272
return now + ( updatedAgo > 14 * 24 * 60 * 60 * 1000 ? 12 : 1 ) * 60 * 60 * 1000 ;
253
273
}
254
274
case 'prByBranch' :
275
+ case 'prsById' :
255
276
case 'prsBySha' : {
256
277
if ( value == null ) return cache === 'prByBranch' ? defaultExpiresAt : 0 /* Never expires */ ;
257
278
258
279
// Open prs expire after 1 hour, but closed/merge prs expire after 12 hours unless recently updated and then expire in 1 hour
259
280
260
- const pr = value as CacheValue < 'prsBySha ' | 'prByBranch ' > ;
281
+ const pr = value as CacheValue < 'prByBranch ' | 'prsById' | 'prsBySha '> ;
261
282
if ( pr . state === 'opened' ) return defaultExpiresAt ;
262
283
263
284
const updatedAgo = now - ( pr . closedDate ?? pr . mergedDate ?? pr . updatedDate ) . getTime ( ) ;
0 commit comments