Skip to content

Commit 2cc9d6a

Browse files
authored
Don't make potentially expensive getObjectDetails and detectObjectType calls for known file extensions (#3447)
1 parent 36d2f75 commit 2cc9d6a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/common/uri.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export interface GitUriOptions {
6060
}
6161

6262
const ImageMimetypes = ['image/png', 'image/gif', 'image/jpeg', 'image/webp', 'image/tiff', 'image/bmp'];
63+
// This list of extensions isn't exhaustive and is just intended to be a quick way to avoid checking the mime type of the file.
64+
const NonImageExtensions = ['.bat', '.c', '.csharp', '.cpp', '.css', '.go', '.html', '.java', '.js', '.md', '.php', '.ts'];
6365

6466
// a 1x1 pixel transparent gif, from http://png-pixel.com/
6567
export const EMPTY_IMAGE_URI = vscode.Uri.parse(
@@ -69,6 +71,10 @@ export const EMPTY_IMAGE_URI = vscode.Uri.parse(
6971
export async function asImageDataURI(uri: vscode.Uri, repository: Repository): Promise<vscode.Uri | undefined> {
7072
try {
7173
const { commit, baseCommit, headCommit, isBase, path } = JSON.parse(uri.query);
74+
const ext = pathUtils.extname(path);
75+
if (NonImageExtensions.includes(ext)) {
76+
return;
77+
}
7278
const ref = uri.scheme === 'review' ? commit : isBase ? baseCommit : headCommit;
7379
const { object } = await repository.getObjectDetails(ref, uri.fsPath);
7480
const { mimetype } = await repository.detectObjectType(object);

0 commit comments

Comments
 (0)