Skip to content

Commit

Permalink
refactor: parallel awaits, remove optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Dec 4, 2023
1 parent 0c85ce6 commit 1830bce
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ import {
ensure,
ensureJsonArray,
ensureString,
isArray,
isBoolean,
isString,
JsonArray,
JsonMap,
Nullable,
Optional,
} from '@salesforce/ts-types';
import { HttpRequest, SaveResult } from 'jsforce';
import { Config } from '../config/config';
Expand Down Expand Up @@ -458,7 +456,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
/**
* Returns the Org object or null if this org is not affiliated with a Dev Hub (according to the local config).
*/
public async getDevHubOrg(): Promise<Optional<Org>> {
public async getDevHubOrg(): Promise<Org | undefined> {
if (this.isDevHubOrg()) {
return this;
} else if (this.getField(Org.Fields.DEV_HUB_USERNAME)) {
Expand Down Expand Up @@ -682,7 +680,10 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
> {
const username = this.getUsername();
if (username) {
const organization = await this.retrieveOrganizationInformation();
const [stateAggregator, organization] = await Promise.all([
StateAggregator.getInstance(),
this.retrieveOrganizationInformation(),
]);
const updateFields = {
[Org.Fields.NAME]: organization.Name,
[Org.Fields.INSTANCE_NAME]: organization.InstanceName,
Expand All @@ -691,7 +692,6 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
[Org.Fields.IS_SCRATCH]: organization.IsSandbox && Boolean(organization.TrialExpirationDate),
[Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate,
};
const stateAggregator = await StateAggregator.getInstance();
stateAggregator.orgs.update(username, updateFields);
await stateAggregator.orgs.write(username);
return updateFields;
Expand All @@ -708,8 +708,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
method: 'GET',
};

const conn = this.getConnection();
await conn.request(requestInfo);
await this.getConnection().request(requestInfo);
}

/**
Expand Down Expand Up @@ -761,7 +760,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
// needs config refactoring to improve
const usernames = contents.usernames ?? [];

if (!isArray(usernames)) {
if (!Array.isArray(usernames)) {
throw new SfError('Usernames is not an array', 'UnexpectedDataFormat');
}

Expand Down Expand Up @@ -847,7 +846,7 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
/**
* Returns the admin username used to create the org.
*/
public getUsername(): Optional<string> {
public getUsername(): string | undefined {
return this.getConnection().getUsername();
}

Expand Down

3 comments on commit 1830bce

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 1830bce Previous: 98762d5 Ratio
Child logger creation 466013 ops/sec (±1.92%) 510994 ops/sec (±2.48%) 1.10
Logging a string on root logger 698015 ops/sec (±9.42%) 896263 ops/sec (±7.43%) 1.28
Logging an object on root logger 549253 ops/sec (±5.93%) 46001 ops/sec (±182.22%) 0.08375193216969229
Logging an object with a message on root logger 16987 ops/sec (±187.75%) 440955 ops/sec (±9.31%) 25.96
Logging an object with a redacted prop on root logger 391346 ops/sec (±16.04%) 514060 ops/sec (±7.93%) 1.31
Logging a nested 3-level object on root logger 357970 ops/sec (±7.43%) 22320 ops/sec (±185.80%) 0.062351593708970025

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 1830bce Previous: 98762d5 Ratio
Logging an object with a message on root logger 16987 ops/sec (±187.75%) 440955 ops/sec (±9.31%) 25.96

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - windows-latest

Benchmark suite Current: 1830bce Previous: 98762d5 Ratio
Child logger creation 317059 ops/sec (±0.95%) 321623 ops/sec (±0.79%) 1.01
Logging a string on root logger 732860 ops/sec (±5.63%) 794560 ops/sec (±6.31%) 1.08
Logging an object on root logger 644953 ops/sec (±7.32%) 611766 ops/sec (±6.48%) 0.95
Logging an object with a message on root logger 9208 ops/sec (±190.13%) 3707 ops/sec (±215.43%) 0.40
Logging an object with a redacted prop on root logger 433535 ops/sec (±18.00%) 472310 ops/sec (±12.10%) 1.09
Logging a nested 3-level object on root logger 328572 ops/sec (±4.62%) 337069 ops/sec (±6.29%) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.