Skip to content

Adds IssueOrPullRequestType to cache keys for issue/PR retrieval #4233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- Fixes cache collision between issues and PRs in autolinks ([#4193](https://github.com/gitkraken/vscode-gitlens/issues/4193))
- Fixes incorrect PR Link Across Azure DevOps Projects ([#4207](https://github.com/gitkraken/vscode-gitlens/issues/4207))
- Fixes detail view incorrectly parses GitHub account in commit message ([#3246](https://github.com/gitkraken/vscode-gitlens/issues/3246))
- Fixes `undefined` sometimes showing for search results in the _Search Commits_ command and _Search & Compare_ view
Expand Down
40 changes: 32 additions & 8 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Container } from './container';
import type { Account } from './git/models/author';
import type { DefaultBranch } from './git/models/defaultBranch';
import type { Issue } from './git/models/issue';
import type { IssueOrPullRequest } from './git/models/issueOrPullRequest';
import type { IssueOrPullRequest, IssueOrPullRequestType } from './git/models/issueOrPullRequest';
import type { PullRequest } from './git/models/pullRequest';
import type { RepositoryMetadata } from './git/models/repositoryMetadata';
import type { HostingIntegration, IntegrationBase, ResourceDescriptor } from './plus/integrations/integration';
Expand Down Expand Up @@ -111,6 +111,7 @@ export class CacheProvider implements Disposable {

getIssueOrPullRequest(
id: string,
type: IssueOrPullRequestType | undefined,
resource: ResourceDescriptor,
integration: IntegrationBase | undefined,
cacheable: Cacheable<IssueOrPullRequest>,
Expand All @@ -119,11 +120,11 @@ export class CacheProvider implements Disposable {
const { key, etag } = getResourceKeyAndEtag(resource, integration);

if (resource == null) {
return this.get('issuesOrPrsById', `id:${id}:${key}`, etag, cacheable, options);
return this.get('issuesOrPrsById', `id:${id}:${key}:${type ?? 'unknown'}`, etag, cacheable, options);
}
return this.get(
'issuesOrPrsByIdAndRepo',
`id:${id}:${key}:${JSON.stringify(resource)}}`,
`id:${id}:${key}:${type ?? 'unknown'}:${JSON.stringify(resource)}}`,
etag,
cacheable,
options,
Expand All @@ -140,11 +141,17 @@ export class CacheProvider implements Disposable {
const { key, etag } = getResourceKeyAndEtag(resource, integration);

if (resource == null) {
return this.get('issuesById', `id:${id}:${key}`, etag, cacheable, options);
return this.get(
'issuesById',
`id:${id}:${key}:${'issue' satisfies IssueOrPullRequestType}`,
etag,
cacheable,
options,
);
}
return this.get(
'issuesByIdAndResource',
`id:${id}:${key}:${JSON.stringify(resource)}}`,
`id:${id}:${key}:${'issue' satisfies IssueOrPullRequestType}:${JSON.stringify(resource)}}`,
etag,
cacheable,
options,
Expand All @@ -161,9 +168,21 @@ export class CacheProvider implements Disposable {
const { key, etag } = getResourceKeyAndEtag(resource, integration);

if (resource == null) {
return this.get('prsById', `id:${id}:${key}`, etag, cacheable, options);
return this.get(
'prsById',
`id:${id}:${key}:${'pullrequest' satisfies IssueOrPullRequestType}`,
etag,
cacheable,
options,
);
}
return this.get('prsById', `id:${id}:${key}:${JSON.stringify(resource)}}`, etag, cacheable, options);
return this.get(
'prsById',
`id:${id}:${key}:${'pullrequest' satisfies IssueOrPullRequestType}:${JSON.stringify(resource)}}`,
etag,
cacheable,
options,
);
}

getPullRequestForBranch(
Expand Down Expand Up @@ -264,7 +283,12 @@ export class CacheProvider implements Disposable {
if (isPromise(item.value)) {
void item.value.then(v => {
if (v != null) {
this.set('issuesOrPrsById', `id:${v.id}:${key}`, v, etag);
this.set(
'issuesOrPrsById',
`id:${v.id}:${key}:${'pullrequest' satisfies IssueOrPullRequestType}`,
v,
etag,
);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/plus/integrations/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ export abstract class IntegrationBase<

const issueOrPR = this.container.cache.getIssueOrPullRequest(
id,
options?.type,
resource,
this,
() => ({
Expand Down