浏览代码

Fixes more perf issues loading PRs in nodes

main
Eric Amodio 2 年前
父节点
当前提交
5937341a86
共有 3 个文件被更改,包括 66 次插入37 次删除
  1. +32
    -18
      src/views/nodes/branchNode.ts
  2. +1
    -1
      src/views/nodes/commitNode.ts
  3. +33
    -18
      src/views/nodes/worktreeNode.ts

+ 32
- 18
src/views/nodes/branchNode.ts 查看文件

@ -13,7 +13,8 @@ import type { GitUser } from '../../git/models/user';
import { gate } from '../../system/decorators/gate';
import { debug, log } from '../../system/decorators/log';
import { map } from '../../system/iterable';
import { getSettledValue } from '../../system/promise';
import type { Deferred } from '../../system/promise';
import { defer, getSettledValue } from '../../system/promise';
import { pad } from '../../system/string';
import type { BranchesView } from '../branchesView';
import type { CommitsView } from '../commitsView';
@ -141,6 +142,8 @@ export class BranchNode
let pullRequest;
let onCompleted: Deferred<void> | undefined;
if (
this.view.config.pullRequests.enabled &&
this.view.config.pullRequests.showForBranches &&
@ -148,26 +151,36 @@ export class BranchNode
) {
pullRequest = this.getState('pullRequest');
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
void this.getAssociatedPullRequest(
branch,
this.root ? { include: [PullRequestState.Open, PullRequestState.Merged] } : undefined,
).then(pr => {
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
if (pr != null && this._children != null) {
this._children.splice(
this._children[0] instanceof CompareBranchNode ? 1 : 0,
0,
new PullRequestNode(this.view, this, pr, branch),
onCompleted = defer<void>();
queueMicrotask(() => {
void this.getAssociatedPullRequest(
branch,
this.root ? { include: [PullRequestState.Open, PullRequestState.Merged] } : undefined,
).then(pr => {
onCompleted?.cancel();
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
if (pr != null && this._children != null) {
this._children.splice(
this._children[0] instanceof CompareBranchNode ? 1 : 0,
0,
new PullRequestNode(this.view, this, pr, branch),
);
}
// Refresh this node to show a spinner while the pull request is loading
this.view.triggerNodeChange(this);
});
// If we are showing the node, then refresh this node to show a spinner while the pull request is loading
if (!this.splatted) {
void onCompleted?.promise.then(
() => this.view.triggerNodeChange(this),
() => {},
);
}
this.view.triggerNodeChange(this);
});
// If we are showing the node, then refresh this node to show a spinner while the pull request is loading
if (!this.splatted) {
queueMicrotask(() => this.view.triggerNodeChange(this));
return [];
}
}
}
@ -314,6 +327,7 @@ export class BranchNode
}
this._children = children;
setTimeout(() => onCompleted?.fulfill(), 0);
}
return this._children;

+ 1
- 1
src/views/nodes/commitNode.ts 查看文件

@ -135,8 +135,8 @@ export class CommitNode extends ViewRefNode
children.splice(0, 0, new PullRequestNode(this.view as ViewsWithCommits, this, pullRequest, commit));
}
onCompleted?.fulfill();
this._children = children;
setTimeout(() => onCompleted?.fulfill(), 1);
}
return this._children;

+ 33
- 18
src/views/nodes/worktreeNode.ts 查看文件

@ -11,7 +11,8 @@ import type { GitWorktree } from '../../git/models/worktree';
import { gate } from '../../system/decorators/gate';
import { debug } from '../../system/decorators/log';
import { map } from '../../system/iterable';
import { getSettledValue } from '../../system/promise';
import type { Deferred} from '../../system/promise';
import { defer, getSettledValue } from '../../system/promise';
import { pad } from '../../system/string';
import type { RepositoriesView } from '../repositoriesView';
import type { WorktreesView } from '../worktreesView';
@ -64,7 +65,9 @@ export class WorktreeNode extends ViewNode
if (this._children == null) {
const branch = this._branch;
const pullRequest = this.getState('pullRequest');
let pullRequest;
let onCompleted: Deferred<void> | undefined;
if (
branch != null &&
@ -72,26 +75,37 @@ export class WorktreeNode extends ViewNode
this.view.config.pullRequests.showForBranches &&
(branch.upstream != null || branch.remote)
) {
pullRequest = this.getState('pullRequest');
if (pullRequest === undefined && this.getState('pendingPullRequest') === undefined) {
void this.getAssociatedPullRequest(branch, {
include: [PullRequestState.Open, PullRequestState.Merged],
}).then(pr => {
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
if (pr != null && this._children != null) {
this._children.splice(
this._children[0] instanceof CompareBranchNode ? 1 : 0,
0,
new PullRequestNode(this.view, this, pr, branch),
onCompleted = defer<void>();
queueMicrotask(() => {
void this.getAssociatedPullRequest(branch, {
include: [PullRequestState.Open, PullRequestState.Merged],
}).then(pr => {
onCompleted?.cancel();
// If we found a pull request, insert it into the children cache (if loaded) and refresh the node
if (pr != null && this._children != null) {
this._children.splice(
this._children[0] instanceof CompareBranchNode ? 1 : 0,
0,
new PullRequestNode(this.view, this, pr, branch),
);
}
// Refresh this node to show a spinner while the pull request is loading
this.view.triggerNodeChange(this);
});
// If we are showing the node, then refresh this node to show a spinner while the pull request is loading
if (!this.splatted) {
void onCompleted?.promise.then(
() => this.view.triggerNodeChange(this),
() => {},
);
}
this.view.triggerNodeChange(this);
});
// If we are showing the node, then refresh this node to show a spinner while the pull request is loading
if (!this.splatted) {
queueMicrotask(() => this.view.triggerNodeChange(this));
return [];
}
}
}
@ -165,6 +179,7 @@ export class WorktreeNode extends ViewNode
}
this._children = children;
setTimeout(() => onCompleted?.fulfill(), 0);
}
return this._children;

正在加载...
取消
保存