Skip to content

Commit b352830

Browse files
author
Alexander Eyers-Taylor
authored
Improve startup time (#1465)
* ArchiveFileSystem: Only parse zips once * CLIServer: Only get version once
1 parent e913165 commit b352830

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

extensions/ql-vscode/src/archive-filesystem-provider.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,26 @@ type Archive = {
167167
dirMap: DirectoryHierarchyMap;
168168
};
169169

170+
async function parse_zip(zipPath: string): Promise<Archive> {
171+
if (!await fs.pathExists(zipPath))
172+
throw vscode.FileSystemError.FileNotFound(zipPath);
173+
const archive: Archive = { unzipped: await unzipper.Open.file(zipPath), dirMap: new Map };
174+
archive.unzipped.files.forEach(f => { ensureFile(archive.dirMap, path.resolve('/', f.path)); });
175+
return archive;
176+
}
177+
170178
export class ArchiveFileSystemProvider implements vscode.FileSystemProvider {
171179
private readOnlyError = vscode.FileSystemError.NoPermissions('write operation attempted, but source archive filesystem is readonly');
172-
private archives: Map<string, Archive> = new Map;
180+
private archives: Map<string, Promise<Archive>> = new Map;
173181

174182
private async getArchive(zipPath: string): Promise<Archive> {
175183
if (!this.archives.has(zipPath)) {
176-
if (!await fs.pathExists(zipPath))
177-
throw vscode.FileSystemError.FileNotFound(zipPath);
178-
const archive: Archive = { unzipped: await unzipper.Open.file(zipPath), dirMap: new Map };
179-
archive.unzipped.files.forEach(f => { ensureFile(archive.dirMap, path.resolve('/', f.path)); });
180-
this.archives.set(zipPath, archive);
184+
this.archives.set(zipPath, parse_zip(zipPath));
181185
}
182-
return this.archives.get(zipPath)!;
186+
return await this.archives.get(zipPath)!;
183187
}
184188

189+
185190
root = new Directory('');
186191

187192
// metadata

extensions/ql-vscode/src/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class CodeQLCliServer implements Disposable {
168168
nullBuffer: Buffer;
169169

170170
/** Version of current cli, lazily computed by the `getVersion()` method */
171-
private _version: SemVer | undefined;
171+
private _version: Promise<SemVer> | undefined;
172172

173173
/**
174174
* The languages supported by the current version of the CLI, computed by `getSupportedLanguages()`.
@@ -985,13 +985,13 @@ export class CodeQLCliServer implements Disposable {
985985

986986
public async getVersion() {
987987
if (!this._version) {
988-
this._version = await this.refreshVersion();
988+
this._version = this.refreshVersion();
989989
// this._version is only undefined upon config change, so we reset CLI-based context key only when necessary.
990990
await commands.executeCommand(
991991
'setContext', 'codeql.supportsEvalLog', await this.cliConstraints.supportsPerQueryEvalLog()
992992
);
993993
}
994-
return this._version;
994+
return await this._version;
995995
}
996996

997997
private async refreshVersion() {

0 commit comments

Comments
 (0)