-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VS Code: fix repo name resolution cache (#5978)
- Ensures the repo name resolution is cached and we don't make unexpected API calls for already resolved remote URLs. - This fix is critical for enterprise clients because the regression significantly increases the repo-name resolution latency, which is used by every enterprise client with Cody Context filters and is on the critical path for every autocomplete request. In my local tests, it adds ~500-600ms to every repo name resolution call. - Closes https://linear.app/sourcegraph/issue/CODY-4139/investigate-repo-name-resolution-latency-increase
- Loading branch information
1 parent
8cff1fc
commit 252b40d
Showing
7 changed files
with
167 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,13 +75,13 @@ describe('gitRemoteUrlsForUri', () => { | |
|
||
const remoteUrls = await gitRemoteUrlsForUri(fileUri) | ||
expect(remoteUrls).toEqual([ | ||
'https://github.com/username/yourproject.git', | ||
'https://github.com/originalauthor/yourproject.git', | ||
'git@backupserver:repositories/yourproject.git', | ||
'https://github.com/originalauthor/yourproject.git', | ||
'https://github.com/username/yourproject.git', | ||
]) | ||
}) | ||
|
||
it('returns `undefined` from the .git/config file with no remotes specified', async () => { | ||
it('returns `[]` from the .git/config file with no remotes specified', async () => { | ||
const { fileUri } = mockFsCalls({ | ||
filePath: '/repo/src/dir/foo.ts', | ||
gitRepoPath: '/repo', | ||
|
@@ -99,10 +99,10 @@ describe('gitRemoteUrlsForUri', () => { | |
}) | ||
|
||
const remoteUrls = await gitRemoteUrlsForUri(fileUri) | ||
expect(remoteUrls).toBe(undefined) | ||
expect(remoteUrls).toEqual([]) | ||
}) | ||
|
||
it('returns `undefined` if .git/config is not found', async () => { | ||
it('returns `[]` if .git/config is not found', async () => { | ||
const statMock = vi | ||
.spyOn(vscode.workspace.fs, 'stat') | ||
.mockResolvedValueOnce({ type: vscode.FileType.File } as vscode.FileStat) | ||
|
@@ -112,7 +112,7 @@ describe('gitRemoteUrlsForUri', () => { | |
const remoteUrls = await gitRemoteUrlsForUri(uri) | ||
|
||
expect(statMock).toBeCalledTimes(5) | ||
expect(remoteUrls).toBe(undefined) | ||
expect(remoteUrls).toEqual([]) | ||
}) | ||
|
||
it('finds remote urls in a submodule', async () => { | ||
|
@@ -175,7 +175,7 @@ describe('gitRemoteUrlsForUri', () => { | |
expect(remoteUrls).toEqual(['https://github.com/nested/submodule.git']) | ||
}) | ||
|
||
it('returns `undefined` for a submodule without a remote url', async () => { | ||
it('returns `[]` for a submodule without a remote url', async () => { | ||
const { fileUri } = mockFsCalls({ | ||
filePath: '/repo/submodule/foo.ts', | ||
gitRepoPath: '/repo', | ||
|
@@ -199,7 +199,7 @@ describe('gitRemoteUrlsForUri', () => { | |
}) | ||
|
||
const remoteUrls = await gitRemoteUrlsForUri(fileUri) | ||
expect(remoteUrls).toBe(undefined) | ||
expect(remoteUrls).toEqual([]) | ||
}) | ||
|
||
it('refuses to work on non-file URIs', async () => { | ||
|
@@ -209,10 +209,10 @@ describe('gitRemoteUrlsForUri', () => { | |
gitConfig: 'a', | ||
}) | ||
|
||
expect(await gitRemoteUrlsForUri(URI.parse('https://example.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://gitlab.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://github.com/foo/bar'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('ssh://[email protected]:foo/bar.git'))).toBe(undefined) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://example.com/foo/bar'))).toEqual([]) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://gitlab.com/foo/bar'))).toEqual([]) | ||
expect(await gitRemoteUrlsForUri(URI.parse('https://github.com/foo/bar'))).toEqual([]) | ||
expect(await gitRemoteUrlsForUri(URI.parse('ssh://[email protected]:foo/bar.git'))).toEqual([]) | ||
expect(statMock).toBeCalledTimes(0) | ||
expect(readFileMock).toBeCalledTimes(0) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.