瀏覽代碼

Adds remote caching

main
Eric Amodio 1 年之前
父節點
當前提交
e02d0c8791
共有 5 個文件被更改,包括 59 次插入48 次删除
  1. +51
    -16
      src/env/node/git/localGitProvider.ts
  2. +1
    -5
      src/git/gitProvider.ts
  3. +1
    -5
      src/git/gitProviderService.ts
  4. +4
    -16
      src/git/models/repository.ts
  5. +2
    -6
      src/plus/github/githubGitProvider.ts

+ 51
- 16
src/env/node/git/localGitProvider.ts 查看文件

@ -123,7 +123,6 @@ import { GitStatusParser } from '../../../git/parsers/statusParser';
import { GitTagParser } from '../../../git/parsers/tagParser';
import { GitTreeParser } from '../../../git/parsers/treeParser';
import { GitWorktreeParser } from '../../../git/parsers/worktreeParser';
import type { RemoteProviders } from '../../../git/remotes/remoteProviders';
import { getRemoteProviderMatcher, loadRemoteProviders } from '../../../git/remotes/remoteProviders';
import type { GitSearch, GitSearchResultData, GitSearchResults, SearchQuery } from '../../../git/search';
import { getGitArgsFromSearchQuery, getSearchQueryComparisonKey } from '../../../git/search';
@ -239,6 +238,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
private readonly _contributorsCache = new Map<string, Promise<GitContributor[]>>();
private readonly _mergeStatusCache = new Map<string, GitMergeStatus | null>();
private readonly _rebaseStatusCache = new Map<string, GitRebaseStatus | null>();
private readonly _remotesCache = new Map<string, Promise<GitRemote[]>>();
private readonly _repoInfoCache = new Map<string, RepositoryInfo>();
private readonly _stashesCache = new Map<string, GitStash | null>();
private readonly _tagsCache = new Map<string, Promise<PagedResult<GitTag>>>();
@ -253,6 +253,11 @@ export class LocalGitProvider implements GitProvider, Disposable {
this.git.setLocator(this.ensureGit.bind(this));
this._disposables.push(
configuration.onDidChange(e => {
if (configuration.changed(e, 'remotes')) {
this.resetCaches('remotes');
}
}, this),
this.container.events.on('git:cache:reset', e =>
e.data.repoPath
? this.resetCache(e.data.repoPath, ...(e.data.caches ?? emptyArray))
@ -280,6 +285,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
this._contributorsCache.delete(`stats|${repo.path}`);
}
if (e.changed(RepositoryChange.Remotes, RepositoryChange.RemoteProviders, RepositoryChangeComparisonMode.Any)) {
this._remotesCache.delete(repo.path);
}
if (e.changed(RepositoryChange.Index, RepositoryChange.Unknown, RepositoryChangeComparisonMode.Any)) {
this._trackedPaths.clear();
}
@ -1069,6 +1078,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
this._contributorsCache.delete(repoPath);
}
if (caches.length === 0 || caches.includes('remotes')) {
this._remotesCache.delete(repoPath);
}
if (caches.length === 0 || caches.includes('stashes')) {
this._stashesCache.delete(repoPath);
}
@ -1098,6 +1111,10 @@ export class LocalGitProvider implements GitProvider, Disposable {
this._contributorsCache.clear();
}
if (caches.length === 0 || caches.includes('remotes')) {
this._remotesCache.clear();
}
if (caches.length === 0 || caches.includes('stashes')) {
this._stashesCache.clear();
}
@ -3989,28 +4006,46 @@ export class LocalGitProvider implements GitProvider, Disposable {
}
@log({ args: { 1: false } })
async getRemotes(
repoPath: string | undefined,
options?: { providers?: RemoteProviders; sort?: boolean },
): Promise<GitRemote[]> {
async getRemotes(repoPath: string | undefined, options?: { sort?: boolean }): Promise<GitRemote[]> {
if (repoPath == null) return [];
const providers = options?.providers ?? loadRemoteProviders(configuration.get('remotes', null));
let remotesPromise = this.useCaching ? this._remotesCache.get(repoPath) : undefined;
if (remotesPromise == null) {
async function load(this: LocalGitProvider): Promise<GitRemote[]> {
const providers = loadRemoteProviders(
configuration.get('remotes', this.container.git.getRepository(repoPath!)?.folder?.uri ?? null),
);
try {
const data = await this.git.remote(repoPath);
const remotes = GitRemoteParser.parse(data, repoPath, getRemoteProviderMatcher(this.container, providers));
if (remotes == null) return [];
try {
const data = await this.git.remote(repoPath!);
const remotes = GitRemoteParser.parse(
data,
repoPath!,
getRemoteProviderMatcher(this.container, providers),
);
if (remotes == null) return [];
if (options?.sort) {
GitRemote.sort(remotes);
return remotes;
} catch (ex) {
this._remotesCache.delete(repoPath!);
Logger.error(ex);
return [];
}
}
return remotes;
} catch (ex) {
Logger.error(ex);
return [];
remotesPromise = load.call(this);
if (this.useCaching) {
this._remotesCache.set(repoPath, remotesPromise);
}
}
const remotes = await remotesPromise;
if (options?.sort) {
GitRemote.sort(remotes);
}
return remotes;
}
@gate()

+ 1
- 5
src/git/gitProvider.ts 查看文件

@ -23,7 +23,6 @@ import type { GitTag, TagSortOptions } from './models/tag';
import type { GitTreeEntry } from './models/tree';
import type { GitUser } from './models/user';
import type { GitWorktree } from './models/worktree';
import type { RemoteProviders } from './remotes/remoteProviders';
import type { GitSearch, SearchQuery } from './search';
export type GitCaches = 'branches' | 'contributors' | 'providers' | 'remotes' | 'stashes' | 'status' | 'tags';
@ -379,10 +378,7 @@ export interface GitProvider extends Disposable {
skip?: number | undefined;
},
): Promise<GitReflog | undefined>;
getRemotes(
repoPath: string | undefined,
options?: { providers?: RemoteProviders; sort?: boolean },
): Promise<GitRemote[]>;
getRemotes(repoPath: string | undefined, options?: { sort?: boolean }): Promise<GitRemote[]>;
getRevisionContent(repoPath: string, path: string, ref: string): Promise<Uint8Array | undefined>;
getStash(repoPath: string | undefined): Promise<GitStash | undefined>;
getStatusForFile(repoPath: string, uri: Uri): Promise<GitStatusFile | undefined>;

+ 1
- 5
src/git/gitProviderService.ts 查看文件

@ -77,7 +77,6 @@ import type { GitTreeEntry } from './models/tree';
import type { GitUser } from './models/user';
import type { GitWorktree } from './models/worktree';
import type { RemoteProvider } from './remotes/remoteProvider';
import type { RemoteProviders } from './remotes/remoteProviders';
import type { RichRemoteProvider } from './remotes/richRemoteProvider';
import type { GitSearch, SearchQuery } from './search';
@ -2272,10 +2271,7 @@ export class GitProviderService implements Disposable {
}
@log({ args: { 1: false } })
async getRemotes(
repoPath: string | Uri | undefined,
options?: { providers?: RemoteProviders; sort?: boolean },
): Promise<GitRemote[]> {
async getRemotes(repoPath: string | Uri | undefined, options?: { sort?: boolean }): Promise<GitRemote[]> {
if (repoPath == null) return [];
const { provider, path } = this.getProvider(repoPath);

+ 4
- 16
src/git/models/repository.ts 查看文件

@ -22,8 +22,6 @@ import { getLogScope } from '../../system/logger.scope';
import { updateRecordValue } from '../../system/object';
import { basename, normalizePath } from '../../system/path';
import type { GitDir, GitProviderDescriptor, GitRepositoryCaches } from '../gitProvider';
import type { RemoteProviders } from '../remotes/remoteProviders';
import { loadRemoteProviders } from '../remotes/remoteProviders';
import type { RichRemoteProvider } from '../remotes/richRemoteProvider';
import type { GitSearch, SearchQuery } from '../search';
import type { BranchSortOptions, GitBranch } from './branch';
@ -216,7 +214,6 @@ export class Repository implements Disposable {
private _fsWatcherDisposable: Disposable | undefined;
private _pendingFileSystemChange?: RepositoryFileSystemChangeEvent;
private _pendingRepoChange?: RepositoryChangeEvent;
private _providers: RemoteProviders | undefined;
private _remotes: Promise<GitRemote[]> | undefined;
private _remotesDisposable: Disposable | undefined;
private _suspended: boolean;
@ -347,13 +344,9 @@ export class Repository implements Disposable {
}
private onConfigurationChanged(e?: ConfigurationChangeEvent) {
if (configuration.changed(e, 'remotes', this.folder?.uri)) {
this._providers = loadRemoteProviders(configuration.get('remotes', this.folder?.uri ?? null));
if (e != null) {
this.resetCaches('remotes');
this.fireChange(RepositoryChange.Remotes);
}
if (e != null && configuration.changed(e, 'remotes', this.folder?.uri)) {
this.resetCaches('remotes');
this.fireChange(RepositoryChange.Remotes);
}
}
@ -685,13 +678,8 @@ export class Repository implements Disposable {
async getRemotes(options?: { filter?: (remote: GitRemote) => boolean; sort?: boolean }): Promise<GitRemote[]> {
if (this._remotes == null) {
if (this._providers == null) {
const remotesCfg = configuration.get('remotes', this.folder?.uri ?? null);
this._providers = loadRemoteProviders(remotesCfg);
}
// Since we are caching the results, always sort
this._remotes = this.container.git.getRemotes(this.path, { providers: this._providers, sort: true });
this._remotes = this.container.git.getRemotes(this.path, { sort: true });
void this.subscribeToRemotes(this._remotes);
}

+ 2
- 6
src/plus/github/githubGitProvider.ts 查看文件

@ -74,7 +74,6 @@ import { getTagId, GitTag, sortTags } from '../../git/models/tag';
import type { GitTreeEntry } from '../../git/models/tree';
import type { GitUser } from '../../git/models/user';
import { isUserMatch } from '../../git/models/user';
import type { RemoteProviders } from '../../git/remotes/remoteProviders';
import { getRemoteProviderMatcher, loadRemoteProviders } from '../../git/remotes/remoteProviders';
import type { GitSearch, GitSearchResultData, GitSearchResults, SearchQuery } from '../../git/search';
import { getSearchQueryComparisonKey, parseSearchQuery } from '../../git/search';
@ -2494,13 +2493,10 @@ export class GitHubGitProvider implements GitProvider, Disposable {
}
@log({ args: { 1: false } })
async getRemotes(
repoPath: string | undefined,
options?: { providers?: RemoteProviders; sort?: boolean },
): Promise<GitRemote[]> {
async getRemotes(repoPath: string | undefined, _options?: { sort?: boolean }): Promise<GitRemote[]> {
if (repoPath == null) return [];
const providers = options?.providers ?? loadRemoteProviders(configuration.get('remotes', null));
const providers = loadRemoteProviders(configuration.get('remotes', null));
const uri = Uri.parse(repoPath, true);
const [, owner, repo] = uri.path.split('/', 3);

Loading…
取消
儲存