Skip to content

Commit f8b4299

Browse files
committed
Reworks "workspace" context
- Improves startup performance - Improves scoped (repo) accuracy checking
1 parent bab40d4 commit f8b4299

File tree

9 files changed

+200
-167
lines changed

9 files changed

+200
-167
lines changed

package.json

Lines changed: 116 additions & 116 deletions
Large diffs are not rendered by default.

src/avatars.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ function getAvatarUriCore(
125125
const avatar = createOrUpdateAvatar(key, email, size, hash, options?.defaultStyle);
126126
if (avatar.uri != null) return avatar.uri;
127127

128-
if (!options?.cached && repoPathOrCommit != null && getContext('gitlens:hasConnectedRemotes')) {
128+
if (
129+
!options?.cached &&
130+
repoPathOrCommit != null &&
131+
getContext('gitlens:repos:withHostingIntegrationsConnected')?.includes(
132+
typeof repoPathOrCommit === 'string' ? repoPathOrCommit : repoPathOrCommit.repoPath,
133+
)
134+
) {
129135
let query = avatarQueue.get(key);
130136
if (query == null && hasAvatarExpired(avatar)) {
131137
query = getAvatarUriFromRemoteProvider(avatar, key, email, repoPathOrCommit, { size: size }).then(

src/constants.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,6 @@ export type ContextKeys = {
681681
'gitlens:gk:organization:ai:enabled': boolean;
682682
'gitlens:gk:organization:drafts:byob': boolean;
683683
'gitlens:gk:organization:drafts:enabled': boolean;
684-
'gitlens:hasConnectedRemotes': boolean;
685-
'gitlens:hasRemotes': boolean;
686-
'gitlens:hasRichRemotes': boolean;
687684
'gitlens:hasVirtualFolders': boolean;
688685
'gitlens:plus': SubscriptionPlanId;
689686
'gitlens:plus:disallowedRepos': string[];
@@ -692,6 +689,9 @@ export type ContextKeys = {
692689
'gitlens:plus:state': SubscriptionState;
693690
'gitlens:prerelease': boolean;
694691
'gitlens:readonly': boolean;
692+
'gitlens:repos:withRemotes': string[];
693+
'gitlens:repos:withHostingIntegrations': string[];
694+
'gitlens:repos:withHostingIntegrationsConnected': string[];
695695
'gitlens:untrusted': boolean;
696696
'gitlens:views:canCompare': boolean;
697697
'gitlens:views:canCompare:file': boolean;
@@ -1178,9 +1178,12 @@ export type TelemetryGlobalContext = {
11781178
'providers.count': number;
11791179
'providers.ids': string;
11801180
'repositories.count': number;
1181-
'repositories.hasConnectedRemotes': boolean;
11821181
'repositories.hasRemotes': boolean;
11831182
'repositories.hasRichRemotes': boolean;
1183+
'repositories.hasConnectedRemotes': boolean;
1184+
'repositories.withRemotes': number;
1185+
'repositories.withHostingIntegrations': number;
1186+
'repositories.withHostingIntegrationsConnected': number;
11841187
'repositories.remoteProviders': string;
11851188
'repositories.schemes': string;
11861189
'repositories.visibility': 'private' | 'public' | 'local' | 'mixed';

src/git/gitProviderService.ts

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,52 +1076,60 @@ export class GitProviderService implements Disposable {
10761076
async function updateRemoteContext(this: GitProviderService) {
10771077
const integrations = configuration.get('integrations.enabled');
10781078

1079-
const telemetryEnabled = this.container.telemetry.enabled;
10801079
const remoteProviders = new Set<string>();
1080+
const reposWithRemotes = new Set<string>();
1081+
const reposWithHostingIntegrations = new Set<string>();
1082+
const reposWithHostingIntegrationsConnected = new Set<string>();
10811083

1082-
let hasRemotes = false;
1083-
let hasRemotesWithIntegrations = false;
1084-
let hasConnectedRemotes = false;
1084+
async function scanRemotes(repo: Repository) {
1085+
let hasSupportedIntegration = false;
1086+
let hasConnectedIntegration = false;
10851087

1086-
if (hasRepositories) {
1087-
for (const repo of this._repositories.values()) {
1088-
if (telemetryEnabled) {
1089-
const remotes = await repo.getRemotes();
1090-
for (const remote of remotes) {
1091-
remoteProviders.add(remote.provider?.id ?? 'unknown');
1092-
}
1093-
}
1094-
1095-
if (!hasConnectedRemotes && integrations) {
1096-
hasConnectedRemotes = await repo.hasRemoteWithIntegration({ includeDisconnected: false });
1097-
1098-
if (hasConnectedRemotes) {
1099-
hasRemotesWithIntegrations = true;
1100-
hasRemotes = true;
1088+
const remotes = await repo.getRemotes();
1089+
for (const remote of remotes) {
1090+
remoteProviders.add(remote.provider?.id ?? 'unknown');
1091+
reposWithRemotes.add(repo.uri.toString());
1092+
reposWithRemotes.add(repo.path);
1093+
1094+
// Skip if integrations are disabled or if we've already found a connected integration
1095+
if (!integrations || (hasSupportedIntegration && hasConnectedIntegration)) continue;
1096+
1097+
if (remote.hasIntegration()) {
1098+
hasSupportedIntegration = true;
1099+
reposWithHostingIntegrations.add(repo.uri.toString());
1100+
reposWithHostingIntegrations.add(repo.path);
1101+
1102+
let connected = remote.maybeIntegrationConnected;
1103+
// If we don't know if we are connected, only check if the remote is the default or there is only one
1104+
// TODO@eamodio is the above still a valid requirement?
1105+
if (connected == null && (remote.default || remotes.length === 1)) {
1106+
const integration = await remote.getIntegration();
1107+
connected = await integration?.isConnected();
11011108
}
1102-
}
1103-
1104-
if (!hasRemotesWithIntegrations && integrations) {
1105-
hasRemotesWithIntegrations = await repo.hasRemoteWithIntegration({ includeDisconnected: true });
11061109

1107-
if (hasRemotesWithIntegrations) {
1108-
hasRemotes = true;
1110+
if (connected) {
1111+
hasConnectedIntegration = true;
1112+
reposWithHostingIntegrationsConnected.add(repo.uri.toString());
1113+
reposWithHostingIntegrationsConnected.add(repo.path);
11091114
}
11101115
}
1111-
1112-
if (!hasRemotes) {
1113-
hasRemotes = await repo.hasRemotes();
1114-
}
1115-
1116-
if (hasRemotes && ((hasRemotesWithIntegrations && hasConnectedRemotes) || !integrations)) break;
11171116
}
11181117
}
11191118

1120-
if (telemetryEnabled) {
1119+
if (hasRepositories) {
1120+
void (await Promise.allSettled(map(this._repositories.values(), scanRemotes)));
1121+
}
1122+
1123+
if (this.container.telemetry.enabled) {
11211124
this.container.telemetry.setGlobalAttributes({
1122-
'repositories.hasRemotes': hasRemotes,
1123-
'repositories.hasRichRemotes': hasRemotesWithIntegrations,
1124-
'repositories.hasConnectedRemotes': hasConnectedRemotes,
1125+
'repositories.hasRemotes': reposWithRemotes.size !== 0,
1126+
'repositories.hasRichRemotes': reposWithHostingIntegrations.size !== 0,
1127+
'repositories.hasConnectedRemotes': reposWithHostingIntegrationsConnected.size !== 0,
1128+
1129+
'repositories.withRemotes': reposWithRemotes.size / 2,
1130+
'repositories.withHostingIntegrations': reposWithHostingIntegrations.size / 2,
1131+
'repositories.withHostingIntegrationsConnected': reposWithHostingIntegrationsConnected.size / 2,
1132+
11251133
'repositories.remoteProviders': join(remoteProviders, ','),
11261134
});
11271135
if (this._sendProviderContextTelemetryDebounced == null) {
@@ -1134,9 +1142,15 @@ export class GitProviderService implements Disposable {
11341142
}
11351143

11361144
await Promise.allSettled([
1137-
setContext('gitlens:hasRemotes', hasRemotes),
1138-
setContext('gitlens:hasRichRemotes', hasRemotesWithIntegrations),
1139-
setContext('gitlens:hasConnectedRemotes', hasConnectedRemotes),
1145+
setContext('gitlens:repos:withRemotes', reposWithRemotes.size ? [...reposWithRemotes] : undefined),
1146+
setContext(
1147+
'gitlens:repos:withHostingIntegrations',
1148+
reposWithHostingIntegrations.size ? [...reposWithHostingIntegrations] : undefined,
1149+
),
1150+
setContext(
1151+
'gitlens:repos:withHostingIntegrationsConnected',
1152+
reposWithHostingIntegrationsConnected.size ? [...reposWithHostingIntegrationsConnected] : undefined,
1153+
),
11401154
]);
11411155
}
11421156

src/plus/webviews/graph/graphWebview.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,13 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
945945
}
946946

947947
private async onGetMissingRefMetadata(e: GetMissingRefsMetadataParams) {
948-
if (this._graph == null || this._refsMetadata === null || !getContext('gitlens:hasConnectedRemotes')) return;
948+
if (
949+
this._graph == null ||
950+
this._refsMetadata === null ||
951+
!getContext('gitlens:repos:withHostingIntegrationsConnected')?.includes(this._graph.repoPath)
952+
) {
953+
return;
954+
}
949955

950956
const repoPath = this._graph.repoPath;
951957

@@ -1549,7 +1555,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
15491555
repo.watchFileSystem(1000),
15501556
repo.onDidChangeFileSystem(this.onRepositoryFileSystemChanged, this),
15511557
onDidChangeContext(key => {
1552-
if (key !== 'gitlens:hasConnectedRemotes') return;
1558+
if (key !== 'gitlens:repos:withHostingIntegrationsConnected') return;
15531559

15541560
this.resetRefsMetadata();
15551561
this.updateRefsMetadata();
@@ -2142,7 +2148,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
21422148
}
21432149

21442150
private resetRefsMetadata(): null | undefined {
2145-
this._refsMetadata = getContext('gitlens:hasConnectedRemotes') ? undefined : null;
2151+
this._refsMetadata = getContext('gitlens:repos:withHostingIntegrationsConnected') ? undefined : null;
21462152
return this._refsMetadata;
21472153
}
21482154

src/views/nodes/branchNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ export class BranchNode
174174
this.view.config.pullRequests.enabled &&
175175
this.view.config.pullRequests.showForBranches &&
176176
(branch.upstream != null || branch.remote) &&
177-
getContext('gitlens:hasConnectedRemotes')
177+
getContext('gitlens:repos:withHostingIntegrationsConnected')?.includes(branch.repoPath)
178178
) {
179179
pullRequest = this.getState('pullRequest');
180180
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {

src/views/nodes/commitNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ export class CommitNode extends ViewRefNode<'commit', ViewsWithCommits | FileHis
9292
if (
9393
this.view.type !== 'tags' &&
9494
!this.unpublished &&
95-
getContext('gitlens:hasConnectedRemotes') &&
9695
this.view.config.pullRequests?.enabled &&
97-
this.view.config.pullRequests?.showForCommits
96+
this.view.config.pullRequests?.showForCommits &&
97+
getContext('gitlens:repos:withHostingIntegrationsConnected')?.includes(commit.repoPath)
9898
) {
9999
pullRequest = this.getState('pullRequest');
100100
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {

src/views/nodes/worktreeNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class WorktreeNode extends CacheableChildrenViewNode<'worktree', ViewsWit
7575
this.view.config.pullRequests.enabled &&
7676
this.view.config.pullRequests.showForBranches &&
7777
(branch.upstream != null || branch.remote) &&
78-
getContext('gitlens:hasConnectedRemotes')
78+
getContext('gitlens:repos:withHostingIntegrationsConnected')?.includes(branch.repoPath)
7979
) {
8080
pullRequest = this.getState('pullRequest');
8181
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {

src/webviews/commitDetails/commitDetailsWebview.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,11 @@ export class CommitDetailsWebviewProvider
14561456
this.updatePendingContext(
14571457
{
14581458
commit: commit,
1459-
richStateLoaded: Boolean(commit?.isUncommitted) || !getContext('gitlens:hasConnectedRemotes'),
1459+
richStateLoaded:
1460+
Boolean(commit?.isUncommitted) ||
1461+
(commit != null
1462+
? !getContext('gitlens:repos:withHostingIntegrationsConnected')?.includes(commit.repoPath)
1463+
: !getContext('gitlens:repos:withHostingIntegrationsConnected')),
14601464
formattedMessage: undefined,
14611465
autolinkedIssues: undefined,
14621466
pullRequest: undefined,

0 commit comments

Comments
 (0)