Skip to content

Commit

Permalink
Revert "Cache the value of extensions.all (microsoft#20222)"
Browse files Browse the repository at this point in the history
This reverts commit db5e96c.
  • Loading branch information
Kartik Raj committed Mar 2, 2023
1 parent b49a70f commit e3784a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
16 changes: 1 addition & 15 deletions src/client/common/application/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import { EXTENSION_ROOT_DIR } from '../constants';
*/
@injectable()
export class Extensions implements IExtensions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private _cachedExtensions?: readonly Extension<any>[];

constructor(@inject(IFileSystem) private readonly fs: IFileSystem) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -35,16 +32,6 @@ export class Extensions implements IExtensions {
return extensions.getExtension(extensionId);
}

private get cachedExtensions() {
if (!this._cachedExtensions) {
this._cachedExtensions = this._cachedExtensions || extensions.all;
extensions.onDidChange(() => {
this._cachedExtensions = this._cachedExtensions || extensions.all;
});
}
return this._cachedExtensions;
}

/**
* Code borrowed from:
* https://github.com/microsoft/vscode-jupyter/blob/67fe33d072f11d6443cf232a06bed0ac5e24682c/src/platform/common/application/extensions.node.ts
Expand All @@ -64,8 +51,7 @@ export class Extensions implements IExtensions {
})
.filter((item) => item && !item.toLowerCase().startsWith(pythonExtRoot))
.filter((item) =>
// Use cached list of extensions as we need this to be fast.
this.cachedExtensions.some(
this.all.some(
(ext) => item!.includes(ext.extensionUri.path) || item!.includes(ext.extensionUri.fsPath),
),
) as string[];
Expand Down
24 changes: 10 additions & 14 deletions src/client/proposedApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,16 @@ export function buildProposedApi(
const extensions = serviceContainer.get<IExtensions>(IExtensions);
const envVarsProvider = serviceContainer.get<IEnvironmentVariablesProvider>(IEnvironmentVariablesProvider);
function sendApiTelemetry(apiName: string, args?: unknown) {
setTimeout(() =>
extensions
.determineExtensionFromCallStack()
.then((info) => {
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
apiName,
extensionId: info.extensionId,
});
traceVerbose(
`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`,
);
})
.ignoreErrors(),
);
extensions
.determineExtensionFromCallStack()
.then((info) => {
sendTelemetryEvent(EventName.PYTHON_ENVIRONMENTS_API, undefined, {
apiName,
extensionId: info.extensionId,
});
traceVerbose(`Extension ${info.extensionId} accessed ${apiName} with args: ${JSON.stringify(args)}`);
})
.ignoreErrors();
}
disposables.push(
discoveryApi.onChanged((e) => {
Expand Down
2 changes: 2 additions & 0 deletions src/test/proposedApi.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ suite('Proposed Extension API', () => {
});

teardown(() => {
// Verify each API method sends telemetry regarding who called the API.
extensions.verifyAll();
sinon.restore();
});

Expand Down

0 comments on commit e3784a6

Please sign in to comment.