Skip to content

Commit

Permalink
Improves view perf when connected to rich remote
Browse files Browse the repository at this point in the history
  - Showing and refreshing the _Commits_ view
  - Expanding commits, branches, and worktrees
  • Loading branch information
eamodio committed Jul 30, 2022
1 parent 317d831 commit b868392
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 176 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -25,6 +25,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Changed

- Greatly improves performance of many view interactions when connected to a rich integration and pull request details are enabled, including:
- Showing and refreshing the _Commits_ view
- Expanding commits, branches, and worktrees
- Remembers chosen filter on files nodes in comparisons when refreshing
- Changes display of filtered state of files nodes in comparisons
- Improves diff stat parsing performance and reduced memory usage
Expand Down
18 changes: 14 additions & 4 deletions src/git/models/branch.ts
Expand Up @@ -4,6 +4,7 @@ import { Starred, WorkspaceStorageKeys } from '../../storage';
import { formatDate, fromNow } from '../../system/date';
import { debug } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
import { cancellable } from '../../system/promise';
import { sortCompare } from '../../system/string';
import { PullRequest, PullRequestState } from './pullRequest';
import { GitBranchReference, GitReference, GitRevision } from './reference';
Expand Down Expand Up @@ -154,18 +155,27 @@ export class GitBranch implements GitBranchReference {
return this.date != null ? fromNow(this.date) : '';
}

private _pullRequest: Promise<PullRequest | undefined> | undefined;

@debug()
async getAssociatedPullRequest(options?: {
avatarSize?: number;
include?: PullRequestState[];
limit?: number;
timeout?: number;
}): Promise<PullRequest | undefined> {
const remote = await this.getRemote();
if (remote == null) return undefined;
if (this._pullRequest == null) {
async function getCore(this: GitBranch): Promise<PullRequest | undefined> {
const remote = await this.getRemote();
if (remote == null) return undefined;

const branch = this.getTrackingWithoutRemote() ?? this.getNameWithoutRemote();
return Container.instance.git.getPullRequestForBranch(branch, remote, options);
}
this._pullRequest = getCore.call(this);
}

const branch = this.getTrackingWithoutRemote() ?? this.getNameWithoutRemote();
return Container.instance.git.getPullRequestForBranch(branch, remote, options);
return cancellable(this._pullRequest, options?.timeout);
}

@memoize()
Expand Down
10 changes: 8 additions & 2 deletions src/git/models/commit.ts
Expand Up @@ -10,9 +10,11 @@ import { cancellable } from '../../system/promise';
import { pad, pluralize } from '../../system/string';
import { PreviousLineComparisonUrisResult } from '../gitProvider';
import { GitUri } from '../gitUri';
import { RichRemoteProvider } from '../remotes/provider';
import { GitFile, GitFileChange, GitFileWorkingTreeStatus } from './file';
import { PullRequest } from './pullRequest';
import { GitReference, GitRevision, GitRevisionReference, GitStashReference } from './reference';
import { GitRemote } from './remote';
import { Repository } from './repository';

const stashNumberRegex = /stash@{(\d+)}/;
Expand Down Expand Up @@ -389,10 +391,14 @@ export class GitCommit implements GitRevisionReference {
}

private _pullRequest: Promise<PullRequest | undefined> | undefined;
async getAssociatedPullRequest(options?: { timeout?: number }): Promise<PullRequest | undefined> {
async getAssociatedPullRequest(options?: {
remote?: GitRemote<RichRemoteProvider>;
timeout?: number;
}): Promise<PullRequest | undefined> {
if (this._pullRequest == null) {
async function getCore(this: GitCommit): Promise<PullRequest | undefined> {
const remote = await this.container.git.getBestRemoteWithRichProvider(this.repoPath);
const remote =
options?.remote ?? (await this.container.git.getBestRemoteWithRichProvider(this.repoPath));
if (remote?.provider == null) return undefined;

return this.container.git.getPullRequestForCommit(this.ref, remote, options);
Expand Down

0 comments on commit b868392

Please sign in to comment.