Skip to content

Commit

Permalink
feat: improve extension start-up performance by not pre loading tooli…
Browse files Browse the repository at this point in the history
…ng API object data
  • Loading branch information
Codeneos committed Aug 6, 2024
1 parent c2edd7c commit 9be0283
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions packages/salesforce/src/schema/compositeSchemaAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,32 @@ export class CompositeSchemaAccess {
public async describe(type: string, field: string): Promise<Field | undefined>;
public async describe(type: string, field?: string): Promise<Field | DescribeSObjectResult | undefined> {
if (!this.schemaStore.get(type)?.describe) {
await this.enqueue(type);
await this.enqueueDescribe(type);
}
return this.schemaStore.get(type, field)?.describe;
}

public async getEntityDefinition(type: string): Promise<EntityDefinition| undefined>{
if (!this.schemaStore.get(type)?.tooling) {
await this.enqueue(type);
await this.enqueueTooling(type);
}
return this.schemaStore.get(type)?.tooling;
}

public async getFieldDefinition(type: string, field: string): Promise<FieldDefinition| undefined>{
if (!this.schemaStore.get(type)?.tooling) {
await this.enqueue(type);
await this.enqueueTooling(type);
}
return this.schemaStore.get(type, field)?.tooling;
}

@cache({ unwrapPromise: true, cacheExceptions: true })
private async enqueue(sobjectType: string) {
const [ describe, entity ] = await Promise.allSettled([
this.describeAccess.describe(sobjectType),
this.toolingAccess.getEntityDefinition(sobjectType)
]);
private async enqueueTooling(sobjectType: string) {
await this.toolingAccess.getEntityDefinition(sobjectType);
}

if (describe.status === 'rejected' && entity.status === 'fulfilled') {
throw new Error(`SObject ${sobjectType} is not accessible by the current user`);
} else if (describe.status === 'rejected') {
throw describe.reason;
}
@cache({ unwrapPromise: true, cacheExceptions: true })
private async enqueueDescribe(sobjectType: string) {
await this.describeAccess.describe(sobjectType);
}
}

0 comments on commit 9be0283

Please sign in to comment.