Skip to content

Commit fffa889

Browse files
committed
Adds AutolinkType to cache keys for issue/PR retrieval
preventing potential cache collisions. (#4193, #4233)
1 parent 25559f5 commit fffa889

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2020

2121
### Fixed
2222

23+
- Fixes cache collision between issues and PRs in autolinks ([#4193](https://github.com/gitkraken/vscode-gitlens/issues/4193))
2324
- Fixes incorrect PR Link Across Azure DevOps Projects ([#4207](https://github.com/gitkraken/vscode-gitlens/issues/4207))
2425
- Fixes detail view incorrectly parses GitHub account in commit message ([#3246](https://github.com/gitkraken/vscode-gitlens/issues/3246))
2526

src/cache.ts

+32-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// import type { EnrichedAutolink } from './annotations/autolinks';
22
import type { Disposable } from './api/gitlens';
3+
import type { AutolinkType } from './autolinks/models/autolinks';
34
import type { Container } from './container';
45
import type { Account } from './git/models/author';
56
import type { DefaultBranch } from './git/models/defaultBranch';
@@ -111,6 +112,7 @@ export class CacheProvider implements Disposable {
111112

112113
getIssueOrPullRequest(
113114
id: string,
115+
type: AutolinkType | undefined,
114116
resource: ResourceDescriptor,
115117
integration: IntegrationBase | undefined,
116118
cacheable: Cacheable<IssueOrPullRequest>,
@@ -119,11 +121,11 @@ export class CacheProvider implements Disposable {
119121
const { key, etag } = getResourceKeyAndEtag(resource, integration);
120122

121123
if (resource == null) {
122-
return this.get('issuesOrPrsById', `id:${id}:${key}`, etag, cacheable, options);
124+
return this.get('issuesOrPrsById', `id:${id}:${key}:${type ?? 'unknown'}`, etag, cacheable, options);
123125
}
124126
return this.get(
125127
'issuesOrPrsByIdAndRepo',
126-
`id:${id}:${key}:${JSON.stringify(resource)}}`,
128+
`id:${id}:${key}:${type ?? 'unknown'}:${JSON.stringify(resource)}}`,
127129
etag,
128130
cacheable,
129131
options,
@@ -140,11 +142,17 @@ export class CacheProvider implements Disposable {
140142
const { key, etag } = getResourceKeyAndEtag(resource, integration);
141143

142144
if (resource == null) {
143-
return this.get('issuesById', `id:${id}:${key}`, etag, cacheable, options);
145+
return this.get(
146+
'issuesById',
147+
`id:${id}:${key}:${'issue' satisfies AutolinkType}`,
148+
etag,
149+
cacheable,
150+
options,
151+
);
144152
}
145153
return this.get(
146154
'issuesByIdAndResource',
147-
`id:${id}:${key}:${JSON.stringify(resource)}}`,
155+
`id:${id}:${key}:${'issue' satisfies AutolinkType}:${JSON.stringify(resource)}}`,
148156
etag,
149157
cacheable,
150158
options,
@@ -161,9 +169,21 @@ export class CacheProvider implements Disposable {
161169
const { key, etag } = getResourceKeyAndEtag(resource, integration);
162170

163171
if (resource == null) {
164-
return this.get('prsById', `id:${id}:${key}`, etag, cacheable, options);
172+
return this.get(
173+
'prsById',
174+
`id:${id}:${key}:${'pullrequest' satisfies AutolinkType}`,
175+
etag,
176+
cacheable,
177+
options,
178+
);
165179
}
166-
return this.get('prsById', `id:${id}:${key}:${JSON.stringify(resource)}}`, etag, cacheable, options);
180+
return this.get(
181+
'prsById',
182+
`id:${id}:${key}:${'pullrequest' satisfies AutolinkType}:${JSON.stringify(resource)}}`,
183+
etag,
184+
cacheable,
185+
options,
186+
);
167187
}
168188

169189
getPullRequestForBranch(
@@ -264,7 +284,12 @@ export class CacheProvider implements Disposable {
264284
if (isPromise(item.value)) {
265285
void item.value.then(v => {
266286
if (v != null) {
267-
this.set('issuesOrPrsById', `id:${v.id}:${key}`, v, etag);
287+
this.set(
288+
'issuesOrPrsById',
289+
`id:${v.id}:${key}:${'pullrequest' satisfies AutolinkType}`,
290+
v,
291+
etag,
292+
);
268293
}
269294
});
270295
}

src/plus/integrations/integration.ts

+1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ export abstract class IntegrationBase<
465465

466466
const issueOrPR = this.container.cache.getIssueOrPullRequest(
467467
id,
468+
options?.type,
468469
resource,
469470
this,
470471
() => ({

0 commit comments

Comments
 (0)