Skip to content

Commit a470ac8

Browse files
committed
Delay load some services until needed
1 parent b032f65 commit a470ac8

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed

src/container.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from './plus/webviews/graph/registration';
3434
import { GraphStatusBarController } from './plus/webviews/graph/statusbar';
3535
import { registerTimelineWebviewPanel, registerTimelineWebviewView } from './plus/webviews/timeline/registration';
36-
import { WorkspacesService } from './plus/workspaces/workspacesService';
36+
import { scheduleAddMissingCurrentWorkspaceRepos, WorkspacesService } from './plus/workspaces/workspacesService';
3737
import { StatusBarController } from './statusbar/statusBarController';
3838
import { executeCommand } from './system/command';
3939
import { configuration } from './system/configuration';
@@ -166,6 +166,7 @@ export class Container {
166166
},
167167
};
168168

169+
private readonly _connection: ServerConnection;
169170
private _disposables: Disposable[];
170171
private _terminalLinks: GitTerminalLinkProvider | undefined;
171172
private _webviews: WebviewsController;
@@ -191,16 +192,15 @@ export class Container {
191192

192193
this._richRemoteProviders = new RichRemoteProviderService(this);
193194

194-
const connection = new ServerConnection(this);
195-
this._disposables.push(connection);
195+
this._disposables.push((this._connection = new ServerConnection(this)));
196196

197-
this._disposables.push((this._accountAuthentication = new AccountAuthenticationProvider(this, connection)));
198-
this._disposables.push((this._subscription = new SubscriptionService(this, connection, previousVersion)));
199-
this._disposables.push((this._workspaces = new WorkspacesService(this, connection)));
197+
this._disposables.push(
198+
(this._accountAuthentication = new AccountAuthenticationProvider(this, this._connection)),
199+
);
200+
this._disposables.push((this._subscription = new SubscriptionService(this, this._connection, previousVersion)));
200201

201202
this._disposables.push((this._git = new GitProviderService(this)));
202203
this._disposables.push(new GitFileSystemProvider(this));
203-
this._disposables.push((this._repositoryPathMapping = getSupportedRepositoryPathMappingProvider(this)));
204204

205205
this._disposables.push((this._uri = new UriService(this)));
206206

@@ -212,7 +212,6 @@ export class Container {
212212
this._disposables.push((this._keyboard = new Keyboard()));
213213
this._disposables.push((this._vsls = new VslsController(this)));
214214
this._disposables.push((this._eventBus = new EventBus()));
215-
this._disposables.push((this._ai = new AIProviderService(this)));
216215

217216
this._disposables.push((this._fileAnnotationController = new FileAnnotationController(this)));
218217
this._disposables.push((this._lineAnnotationController = new LineAnnotationController(this)));
@@ -274,6 +273,8 @@ export class Container {
274273
context.subscriptions.push({
275274
dispose: () => this._disposables.reverse().forEach(d => void d.dispose()),
276275
});
276+
277+
scheduleAddMissingCurrentWorkspaceRepos(this);
277278
}
278279

279280
deactivate() {
@@ -334,8 +335,11 @@ export class Container {
334335
return this._actionRunners;
335336
}
336337

337-
private readonly _ai: AIProviderService;
338+
private _ai: AIProviderService | undefined;
338339
get ai() {
340+
if (this._ai == null) {
341+
this._disposables.push((this._ai = new AIProviderService(this)));
342+
}
339343
return this._ai;
340344
}
341345

@@ -529,8 +533,11 @@ export class Container {
529533
return this._lineTracker;
530534
}
531535

532-
private readonly _repositoryPathMapping: RepositoryPathMappingProvider;
536+
private _repositoryPathMapping: RepositoryPathMappingProvider | undefined;
533537
get repositoryPathMapping() {
538+
if (this._repositoryPathMapping == null) {
539+
this._disposables.push((this._repositoryPathMapping = getSupportedRepositoryPathMappingProvider(this)));
540+
}
534541
return this._repositoryPathMapping;
535542
}
536543

@@ -632,8 +639,11 @@ export class Container {
632639
return this._vsls;
633640
}
634641

635-
private _workspaces: WorkspacesService;
642+
private _workspaces: WorkspacesService | undefined;
636643
get workspaces() {
644+
if (this._workspaces == null) {
645+
this._disposables.push((this._workspaces = new WorkspacesService(this, this._connection)));
646+
}
637647
return this._workspaces;
638648
}
639649

src/plus/workspaces/workspacesService.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,11 @@ export class WorkspacesService implements Disposable {
6060
) {
6161
this._workspacesApi = new WorkspacesApi(this.container, this.connection);
6262
this._workspacesPathProvider = getSupportedWorkspacesPathMappingProvider();
63-
this._currentWorkspaceId = workspace.getConfiguration('gitkraken')?.get<string>('workspaceId');
63+
this._currentWorkspaceId = getCurrentWorkspaceId();
6464
this._currentWorkspaceAutoAddSetting =
6565
workspace.getConfiguration('gitkraken')?.get<WorkspaceAutoAddSetting>('workspaceAutoAddSetting') ??
6666
WorkspaceAutoAddSetting.Disabled;
6767
this._disposable = Disposable.from(container.subscription.onDidChange(this.onSubscriptionChanged, this));
68-
if (this._currentWorkspaceId != null) {
69-
setTimeout(() => this.addMissingCurrentWorkspaceRepos(), 10000);
70-
}
7168
}
7269

7370
dispose(): void {
@@ -1342,6 +1339,17 @@ function getRemoteDescriptor(remote: GitRemote): RemoteDescriptor | undefined {
13421339
};
13431340
}
13441341

1342+
function getCurrentWorkspaceId(): string | undefined {
1343+
return workspace.getConfiguration('gitkraken')?.get<string>('workspaceId');
1344+
}
1345+
1346+
export function scheduleAddMissingCurrentWorkspaceRepos(container: Container) {
1347+
const currentWorkspaceId = getCurrentWorkspaceId();
1348+
if (currentWorkspaceId == null) return;
1349+
1350+
setTimeout(() => container.workspaces.addMissingCurrentWorkspaceRepos(), 10000);
1351+
}
1352+
13451353
// TODO: Add back in once we think through virtual repository support a bit more.
13461354
/* function encodeAuthority<T>(scheme: string, metadata?: T): string {
13471355
return `${scheme}${metadata != null ? `+${encodeUtf8Hex(JSON.stringify(metadata))}` : ''}`;

src/views/workspacesView.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@ import { registerViewCommand } from './viewCommands';
1818

1919
export class WorkspacesView extends ViewBase<'workspaces', WorkspacesViewNode, RepositoriesViewConfig> {
2020
protected readonly configKey = 'repositories';
21-
private _disposable: Disposable;
21+
private _disposable: Disposable | undefined;
2222

2323
constructor(container: Container) {
2424
super(container, 'workspaces', 'Workspaces', 'workspaceView');
2525

26-
this._disposable = Disposable.from(
27-
this.container.workspaces.onDidResetWorkspaces(() => void this.ensureRoot().triggerChange(true)),
28-
);
2926
this.description = `PREVIEW\u00a0\u00a0☁️`;
3027
}
3128

3229
override dispose() {
33-
this._disposable.dispose();
30+
this._disposable?.dispose();
3431
super.dispose();
3532
}
3633

@@ -44,6 +41,13 @@ export class WorkspacesView extends ViewBase<'workspaces', WorkspacesViewNode, R
4441

4542
override async show(options?: { preserveFocus?: boolean | undefined }): Promise<void> {
4643
if (!(await ensurePlusFeaturesEnabled())) return;
44+
45+
if (this._disposable == null) {
46+
this._disposable = Disposable.from(
47+
this.container.workspaces.onDidResetWorkspaces(() => void this.ensureRoot().triggerChange(true)),
48+
);
49+
}
50+
4751
return super.show(options);
4852
}
4953

0 commit comments

Comments
 (0)