Skip to content

Commit

Permalink
feat: return a value, use that instead of mutating state
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 27, 2023
1 parent f5c6116 commit b311cb1
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions src/org/org.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,12 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
* using {@link Org.retrieveOrganizationInformation}.
*/
public async determineIfScratch(): Promise<boolean> {
let cache = this.getField(Org.Fields.IS_SCRATCH);

if (cache === undefined) {
await this.updateLocalInformation();
cache = this.getField(Org.Fields.IS_SCRATCH);
const cache = this.getField<boolean | undefined>(Org.Fields.IS_SCRATCH);
if (cache !== undefined) {
return cache;
}
return cache as boolean;
const updated = await this.updateLocalInformation();
return updated?.isScratch === true;
}

/**
Expand All @@ -645,13 +644,12 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
* using {@link Org.retrieveOrganizationInformation}.
*/
public async determineIfSandbox(): Promise<boolean> {
let cache = this.getField(Org.Fields.IS_SANDBOX);

if (cache === undefined) {
await this.updateLocalInformation();
cache = this.getField(Org.Fields.IS_SANDBOX);
const cache = this.getField<boolean | undefined>(Org.Fields.IS_SANDBOX);
if (cache !== undefined) {
return cache;
}
return cache as boolean;
const updated = await this.updateLocalInformation();
return updated?.isSandbox === true;
}

/**
Expand All @@ -670,22 +668,32 @@ export class Org extends AsyncOptionalCreatable<Org.Options> {
* Some organization information is locally cached, such as if the org name or if it is a scratch org.
* This method populates/updates the filesystem from information retrieved from the org.
*/
public async updateLocalInformation(): Promise<void> {
public async updateLocalInformation(): Promise<
| {
name: string;
instanceName: string;
namespacePrefix: string | null;
isSandbox: boolean;
isScratch: boolean;
trailExpirationDate: string | null;
}
| undefined
> {
const username = this.getUsername();
if (username) {
const organization = await this.retrieveOrganizationInformation();
const isScratch = organization.IsSandbox && Boolean(organization.TrialExpirationDate);
const isSandbox = organization.IsSandbox && !organization.TrialExpirationDate;
const stateAggregator = await StateAggregator.getInstance();
stateAggregator.orgs.update(username, {
const updateFields = {
[Org.Fields.NAME]: organization.Name,
[Org.Fields.INSTANCE_NAME]: organization.InstanceName,
[Org.Fields.NAMESPACE_PREFIX]: organization.NamespacePrefix,
[Org.Fields.IS_SANDBOX]: isSandbox,
[Org.Fields.IS_SCRATCH]: isScratch,
[Org.Fields.IS_SANDBOX]: organization.IsSandbox && Boolean(organization.TrialExpirationDate),
[Org.Fields.IS_SCRATCH]: organization.IsSandbox && !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 Down

3 comments on commit b311cb1

@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: b311cb1 Previous: 0d19545 Ratio
Child logger creation 476355 ops/sec (±2.12%) 478674 ops/sec (±1.22%) 1.00
Logging a string on root logger 856792 ops/sec (±8.99%) 774292 ops/sec (±6.99%) 0.90
Logging an object on root logger 591326 ops/sec (±7.25%) 547792 ops/sec (±7.65%) 0.93
Logging an object with a message on root logger 4188 ops/sec (±224.09%) 13660 ops/sec (±197.88%) 3.26
Logging an object with a redacted prop on root logger 466863 ops/sec (±9.47%) 488915 ops/sec (±4.98%) 1.05
Logging a nested 3-level object on root logger 365974 ops/sec (±9.09%) 360269 ops/sec (±6.79%) 0.98

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: b311cb1 Previous: 0d19545 Ratio
Logging an object with a message on root logger 4188 ops/sec (±224.09%) 13660 ops/sec (±197.88%) 3.26

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: b311cb1 Previous: 0d19545 Ratio
Child logger creation 322390 ops/sec (±2.95%) 339471 ops/sec (±3.14%) 1.05
Logging a string on root logger 786173 ops/sec (±5.91%) 869530 ops/sec (±5.49%) 1.11
Logging an object on root logger 591125 ops/sec (±6.11%) 650217 ops/sec (±6.14%) 1.10
Logging an object with a message on root logger 8151 ops/sec (±201.85%) 1581 ops/sec (±276.45%) 0.19
Logging an object with a redacted prop on root logger 470388 ops/sec (±7.19%) 433324 ops/sec (±12.16%) 0.92
Logging a nested 3-level object on root logger 345341 ops/sec (±5.11%) 337933 ops/sec (±5.45%) 0.98

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

Please sign in to comment.