Skip to content

Commit 628fed7

Browse files
committed
Adds AutolinkType to cache keys for issue/PR retrieval
preventing potential cache collisions. (#4193, #4233)
1 parent 96ed149 commit 628fed7

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

CHANGELOG.md

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

2323
### Fixed
2424

25+
- Fixes cache collision between issues and PRs in autolinks ([#4193](https://github.com/gitkraken/vscode-gitlens/issues/4193))
2526
- Fixes incorrect PR Link Across Azure DevOps Projects ([#4207](https://github.com/gitkraken/vscode-gitlens/issues/4207))
2627
- Fixes detail view incorrectly parses GitHub account in commit message ([#3246](https://github.com/gitkraken/vscode-gitlens/issues/3246))
2728
- Fixes `undefined` sometimes showing for search results in the _Search Commits_ command and _Search & Compare_ view

src/cache.ts

+32-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Container } from './container';
44
import type { Account } from './git/models/author';
55
import type { DefaultBranch } from './git/models/defaultBranch';
66
import type { Issue } from './git/models/issue';
7-
import type { IssueOrPullRequest } from './git/models/issueOrPullRequest';
7+
import type { IssueOrPullRequest, IssueOrPullRequestType } from './git/models/issueOrPullRequest';
88
import type { PullRequest } from './git/models/pullRequest';
99
import type { RepositoryMetadata } from './git/models/repositoryMetadata';
1010
import type { HostingIntegration, IntegrationBase, ResourceDescriptor } from './plus/integrations/integration';
@@ -111,6 +111,7 @@ export class CacheProvider implements Disposable {
111111

112112
getIssueOrPullRequest(
113113
id: string,
114+
type: IssueOrPullRequestType | undefined,
114115
resource: ResourceDescriptor,
115116
integration: IntegrationBase | undefined,
116117
cacheable: Cacheable<IssueOrPullRequest>,
@@ -119,11 +120,11 @@ export class CacheProvider implements Disposable {
119120
const { key, etag } = getResourceKeyAndEtag(resource, integration);
120121

121122
if (resource == null) {
122-
return this.get('issuesOrPrsById', `id:${id}:${key}`, etag, cacheable, options);
123+
return this.get('issuesOrPrsById', `id:${id}:${key}:${type ?? 'unknown'}`, etag, cacheable, options);
123124
}
124125
return this.get(
125126
'issuesOrPrsByIdAndRepo',
126-
`id:${id}:${key}:${JSON.stringify(resource)}}`,
127+
`id:${id}:${key}:${type ?? 'unknown'}:${JSON.stringify(resource)}}`,
127128
etag,
128129
cacheable,
129130
options,
@@ -140,11 +141,17 @@ export class CacheProvider implements Disposable {
140141
const { key, etag } = getResourceKeyAndEtag(resource, integration);
141142

142143
if (resource == null) {
143-
return this.get('issuesById', `id:${id}:${key}`, etag, cacheable, options);
144+
return this.get(
145+
'issuesById',
146+
`id:${id}:${key}:${'issue' satisfies IssueOrPullRequestType}`,
147+
etag,
148+
cacheable,
149+
options,
150+
);
144151
}
145152
return this.get(
146153
'issuesByIdAndResource',
147-
`id:${id}:${key}:${JSON.stringify(resource)}}`,
154+
`id:${id}:${key}:${'issue' satisfies IssueOrPullRequestType}:${JSON.stringify(resource)}}`,
148155
etag,
149156
cacheable,
150157
options,
@@ -161,9 +168,21 @@ export class CacheProvider implements Disposable {
161168
const { key, etag } = getResourceKeyAndEtag(resource, integration);
162169

163170
if (resource == null) {
164-
return this.get('prsById', `id:${id}:${key}`, etag, cacheable, options);
171+
return this.get(
172+
'prsById',
173+
`id:${id}:${key}:${'pullrequest' satisfies IssueOrPullRequestType}`,
174+
etag,
175+
cacheable,
176+
options,
177+
);
165178
}
166-
return this.get('prsById', `id:${id}:${key}:${JSON.stringify(resource)}}`, etag, cacheable, options);
179+
return this.get(
180+
'prsById',
181+
`id:${id}:${key}:${'pullrequest' satisfies IssueOrPullRequestType}:${JSON.stringify(resource)}}`,
182+
etag,
183+
cacheable,
184+
options,
185+
);
167186
}
168187

169188
getPullRequestForBranch(
@@ -264,7 +283,12 @@ export class CacheProvider implements Disposable {
264283
if (isPromise(item.value)) {
265284
void item.value.then(v => {
266285
if (v != null) {
267-
this.set('issuesOrPrsById', `id:${v.id}:${key}`, v, etag);
286+
this.set(
287+
'issuesOrPrsById',
288+
`id:${v.id}:${key}:${'pullrequest' satisfies IssueOrPullRequestType}`,
289+
v,
290+
etag,
291+
);
268292
}
269293
});
270294
}

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)