Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve perf when telemetry is disabled #546

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/hooks/telemetryPrerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { join } from 'node:path';
import { Hook, Performance } from '@oclif/core';
import { SfError, Lifecycle } from '@salesforce/core';
import { JsonMap } from '@salesforce/ts-types';
import type { Hook } from '@oclif/core';
import type { SfError } from '@salesforce/core';
import type { JsonMap } from '@salesforce/ts-types';
import enabledCheck from '@salesforce/telemetry/enabledCheck';
import Telemetry from '../telemetry.js';
import { TelemetryGlobal } from '../telemetryGlobal.js';
import { CommandExecution } from '../commandExecution.js';
import type { TelemetryGlobal } from '../telemetryGlobal.js';
import { debug } from '../debugger.js';

declare const global: TelemetryGlobal;
Expand All @@ -38,6 +35,14 @@ const hook: Hook.Prerun = async function (options): Promise<void> {
}

try {
const [path, Performance, Lifecycle, Telemetry, CommandExecution] = await Promise.all([
await import('node:path'),
(await import('@oclif/core')).Performance,
(await import('@salesforce/core')).Lifecycle,
(await import('../telemetry.js')).default,
(await import('../commandExecution.js')).CommandExecution,
]);

const errors: Array<{ event: JsonMap; error: SfError }> = [];

// Instantiating telemetry shows data collection warning.
Expand Down Expand Up @@ -118,7 +123,8 @@ const hook: Hook.Prerun = async function (options): Promise<void> {
telemetry.record({
eventName: 'INSTALL',
installType:
this.config.binPath?.includes(join('sfdx', 'client')) ?? this.config.binPath?.includes(join('sf', 'client'))
this.config.binPath?.includes(path.join('sfdx', 'client')) ??
this.config.binPath?.includes(path.join('sf', 'client'))
? 'installer'
: 'npm',
platform: this.config.platform,
Expand Down