Skip to content

Commit bf6f0f3

Browse files
committed
Improves loading performance of the Commits view
1 parent 89ba0e3 commit bf6f0f3

File tree

3 files changed

+45
-45
lines changed

3 files changed

+45
-45
lines changed

src/views/nodes/branchNode.ts

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ViewShowBranchComparison } from '../../config';
55
import { GlyphChars } from '../../constants';
66
import type { Colors } from '../../constants.colors';
77
import type { Container } from '../../container';
8+
import type { GitRepositoryService } from '../../git/gitRepositoryService';
89
import type { GitUri } from '../../git/gitUri';
910
import { unknownGitUri } from '../../git/gitUri';
1011
import type { GitBranch } from '../../git/models/branch';
@@ -223,15 +224,13 @@ export class BranchNode
223224
const [
224225
logResult,
225226
getBranchAndTagTipsResult,
226-
statusResult,
227227
pausedOpStatusResult,
228228
unpublishedCommitsResult,
229229
baseResult,
230230
targetResult,
231231
] = await Promise.allSettled([
232-
this.getLog(),
232+
this.getLog(svc),
233233
svc.getBranchesAndTagsTipsLookup(branch.name),
234-
this.options.showStatus && branch.current ? svc.status.getStatus() : undefined,
235234
this.options.showStatus && branch.current ? svc.status.getPausedOperationStatus?.() : undefined,
236235
!branch.remote
237236
? getBranchAheadRange(svc, branch).then(range =>
@@ -253,7 +252,6 @@ export class BranchNode
253252

254253
const children = [];
255254

256-
const status = getSettledValue(statusResult);
257255
const pausedOpsStatus = getSettledValue(pausedOpStatusResult);
258256
const unpublishedCommits = new Set(getSettledValue(unpublishedCommitsResult));
259257

@@ -262,17 +260,7 @@ export class BranchNode
262260
}
263261

264262
if (pausedOpsStatus != null) {
265-
children.push(
266-
new PausedOperationStatusNode(
267-
this.view,
268-
this,
269-
branch,
270-
pausedOpsStatus,
271-
status ??
272-
(await this.view.container.git.getRepositoryService(this.uri.repoPath!).status.getStatus()),
273-
this.root,
274-
),
275-
);
263+
children.push(new PausedOperationStatusNode(this.view, this, branch, pausedOpsStatus, this.root));
276264
} else if (this.options.showTracking) {
277265
const status = {
278266
ref: branch.ref,
@@ -471,7 +459,7 @@ export class BranchNode
471459
}
472460

473461
private _log: GitLog | undefined;
474-
private async getLog() {
462+
private async getLog(svc: GitRepositoryService): Promise<GitLog | undefined> {
475463
if (this._log == null) {
476464
let limit =
477465
this.limit ??
@@ -484,14 +472,12 @@ export class BranchNode
484472
limit = Math.min(ahead + 1, limit * 2);
485473
}
486474

487-
this._log = await this.view.container.git
488-
.getRepositoryService(this.uri.repoPath!)
489-
.commits.getLog(this.ref.ref, {
490-
limit: limit,
491-
authors: this.options?.authors,
492-
merges: this.options?.showMergeCommits,
493-
stashes: this.options?.showStashes,
494-
});
475+
this._log = await svc.commits.getLog(this.ref.ref, {
476+
limit: limit,
477+
authors: this.options?.authors,
478+
merges: this.options?.showMergeCommits,
479+
stashes: this.options?.showStashes,
480+
});
495481
}
496482

497483
return this._log;
@@ -503,11 +489,8 @@ export class BranchNode
503489

504490
@gate()
505491
async loadMore(limit?: number | { until?: any }): Promise<void> {
506-
let log = await window.withProgress(
507-
{
508-
location: { viewId: this.view.id },
509-
},
510-
() => this.getLog(),
492+
let log = await window.withProgress({ location: { viewId: this.view.id } }, () =>
493+
this.getLog(this.view.container.git.getRepositoryService(this.uri.repoPath!)),
511494
);
512495
if (!log?.hasMore) return;
513496

src/views/nodes/pausedOperationStatusNode.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { GitPausedOperationStatus } from '../../git/models/pausedOperationS
66
import type { GitStatus } from '../../git/models/status';
77
import { pausedOperationStatusStringsByType } from '../../git/utils/pausedOperationStatus.utils';
88
import { getReferenceLabel } from '../../git/utils/reference.utils';
9+
import { Lazy } from '../../system/lazy';
910
import { pluralize } from '../../system/string';
1011
import type { ViewsWithCommits } from '../viewBase';
1112
import { createViewDecorationUri } from '../viewDecorationProvider';
@@ -14,29 +15,44 @@ import { MergeConflictFilesNode } from './mergeConflictFilesNode';
1415
import { RebaseCommitNode } from './rebaseCommitNode';
1516

1617
export class PausedOperationStatusNode extends ViewNode<'paused-operation-status', ViewsWithCommits> {
18+
private _status: GitStatus | undefined;
19+
private readonly _lazyStatus: Lazy<GitStatus | Promise<GitStatus | undefined> | undefined>;
20+
1721
constructor(
1822
view: ViewsWithCommits,
1923
protected override readonly parent: ViewNode,
2024
public readonly branch: GitBranch,
2125
public readonly pausedOpStatus: GitPausedOperationStatus,
22-
public readonly status: GitStatus | undefined,
2326
// Specifies that the node is shown as a root
2427
public readonly root: boolean,
28+
status?: GitStatus | undefined,
2529
) {
2630
super('paused-operation-status', GitUri.fromRepoPath(pausedOpStatus.repoPath), view, parent);
2731

2832
this.updateContext({ branch: branch, root: root, pausedOperation: pausedOpStatus.type });
2933
this._uniqueId = getViewNodeId(this.type, this.context);
34+
35+
this._status = status;
36+
this._lazyStatus = new Lazy<GitStatus | Promise<GitStatus | undefined> | undefined>(
37+
() =>
38+
status ??
39+
this.view.container.git
40+
.getRepositoryService(this.repoPath)
41+
.status.getStatus()
42+
.then(s => (this._status = s)),
43+
);
3044
}
3145

3246
get repoPath(): string {
3347
return this.uri.repoPath!;
3448
}
3549

3650
async getChildren(): Promise<ViewNode[]> {
51+
const status = await this._lazyStatus.value;
52+
3753
if (this.pausedOpStatus.type !== 'rebase') {
38-
return this.status?.hasConflicts
39-
? [new MergeConflictFilesNode(this.view, this, this.pausedOpStatus, this.status.conflicts)]
54+
return status?.hasConflicts
55+
? [new MergeConflictFilesNode(this.view, this, this.pausedOpStatus, status.conflicts)]
4056
: [];
4157
}
4258

@@ -55,17 +71,19 @@ export class PausedOperationStatusNode extends ViewNode<'paused-operation-status
5571
}
5672
}
5773

58-
if (this.status?.hasConflicts) {
59-
children.push(new MergeConflictFilesNode(this.view, this, this.pausedOpStatus, this.status.conflicts));
74+
if (status?.hasConflicts) {
75+
children.push(new MergeConflictFilesNode(this.view, this, this.pausedOpStatus, status.conflicts));
6076
}
6177

6278
return children;
6379
}
6480

65-
getTreeItem(): TreeItem {
66-
const hasConflicts = this.status?.hasConflicts === true;
81+
async getTreeItem(): Promise<TreeItem> {
82+
const status = await this._lazyStatus.value;
83+
84+
const hasConflicts = status?.hasConflicts === true;
6785
const hasChildren =
68-
this.status?.hasConflicts ||
86+
status?.hasConflicts ||
6987
(this.pausedOpStatus.type === 'rebase' &&
7088
this.pausedOpStatus.steps.total > 0 &&
7189
this.pausedOpStatus.steps.current.commit != null);
@@ -91,7 +109,7 @@ export class PausedOperationStatusNode extends ViewNode<'paused-operation-status
91109
break;
92110
}
93111

94-
item.description = hasConflicts ? pluralize('conflict', this.status.conflicts.length) : undefined;
112+
item.description = hasConflicts ? pluralize('conflict', status.conflicts.length) : undefined;
95113

96114
const iconColor: Colors = hasConflicts
97115
? 'gitlens.decorations.statusMergingOrRebasingConflictForegroundColor'
@@ -108,7 +126,7 @@ export class PausedOperationStatusNode extends ViewNode<'paused-operation-status
108126
}
109127

110128
private get label(): string {
111-
const hasConflicts = this.status?.hasConflicts === true;
129+
const hasConflicts = this._status?.hasConflicts === true;
112130

113131
if (this.pausedOpStatus.type !== 'rebase') {
114132
const strings = pausedOperationStatusStringsByType[this.pausedOpStatus.type];
@@ -136,17 +154,16 @@ export class PausedOperationStatusNode extends ViewNode<'paused-operation-status
136154
}
137155

138156
private get tooltip(): MarkdownString {
139-
const hasConflicts = this.status?.hasConflicts === true;
157+
const status = this._status;
158+
const hasConflicts = status?.hasConflicts === true;
140159

141160
let tooltip;
142161
if (this.pausedOpStatus.type !== 'rebase') {
143162
const strings = pausedOperationStatusStringsByType[this.pausedOpStatus.type];
144163
tooltip = `${strings.label} ${getReferenceLabel(this.pausedOpStatus.incoming, { label: false })} ${
145164
strings.directionality
146165
} ${getReferenceLabel(this.pausedOpStatus.current, { label: false })}${
147-
hasConflicts
148-
? `\n\nResolve ${pluralize('conflict', this.status.conflicts.length)} before continuing`
149-
: ''
166+
hasConflicts ? `\n\nResolve ${pluralize('conflict', status.conflicts.length)} before continuing` : ''
150167
}`;
151168
} else {
152169
const started = this.pausedOpStatus.steps.total > 0;
@@ -161,7 +178,7 @@ export class PausedOperationStatusNode extends ViewNode<'paused-operation-status
161178
this.pausedOpStatus.steps.total
162179
}${
163180
hasConflicts
164-
? `\\\nResolve ${pluralize('conflict', this.status.conflicts.length)} before continuing`
181+
? `\\\nResolve ${pluralize('conflict', status.conflicts.length)} before continuing`
165182
: ''
166183
}`
167184
: ''

src/views/nodes/repositoryNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class RepositoryNode extends SubscribeableViewNode<'repository', ViewsWit
9898

9999
const pausedOpStatus = await this.repo.git.status.getPausedOperationStatus?.();
100100
if (pausedOpStatus != null) {
101-
children.push(new PausedOperationStatusNode(this.view, this, branch, pausedOpStatus, status, true));
101+
children.push(new PausedOperationStatusNode(this.view, this, branch, pausedOpStatus, true, status));
102102
} else if (this.view.config.showUpstreamStatus) {
103103
if (status.upstream) {
104104
if (!status.upstream.state.behind && !status.upstream.state.ahead) {

0 commit comments

Comments
 (0)