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 2 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
20 changes: 12 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,12 @@ const hook: Hook.Prerun = async function (options): Promise<void> {
}

try {
const path = await import('node:path');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perf: you can Promise.all these

const { Performance } = await import('@oclif/core');
const { Lifecycle } = await import('@salesforce/core');
const { default: Telemetry } = await import('../telemetry.js');
const { CommandExecution } = await import('../commandExecution.js');

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

// Instantiating telemetry shows data collection warning.
Expand Down Expand Up @@ -118,7 +121,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
Loading