-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
chore: Salesforce - optimize getContact
method [CAL-4940]
#18289
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Skipped Deployments
|
hosts: { | ||
user: { | ||
email: string; | ||
}; | ||
}[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include hosts emails in the initial query here so we don't need to make a second DB query when checking if the CRM record owner is a host.
@@ -92,6 +92,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => | |||
select: { | |||
name: true, | |||
username: true, | |||
email: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include email in the hosts query
} | ||
} | ||
// If creating events on contacts or leads | ||
soql = `SELECT Id, Email, OwnerId, AccountId, Account.Owner.Email, Account.Website FROM ${SalesforceRecordEnum.CONTACT} WHERE Email = '${attendeeEmail}' AND AccountId != null`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make use of SOQL nested queries to reduce the amount of calls we're making to Salesforce
if (!records.length) { | ||
log.info("No records found"); | ||
return []; | ||
} | ||
|
||
// Handle owner information |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huge win is removing the need to make a separate query for the owner information
|
||
let records: ContactRecord[] = []; | ||
|
||
// If falling back to contacts, check for the contact before returning the leads or empty array | ||
if ( | ||
appOptions.createEventOn === SalesforceRecordEnum.LEAD && | ||
appOptions.createEventOnLeadCheckForContact | ||
appOptions.createEventOnLeadCheckForContact && | ||
!forRoundRobinSkip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need this logic for event creation.
@@ -915,6 +826,51 @@ export default class SalesforceCRMService implements CRM { | |||
return this.getDominantAccountId(response.records as { AccountId: string }[]); | |||
} | |||
|
|||
private async getAccountBasedOnEmailDomainOfContacts(email: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to getAccountIdBasedOnEmailDomainOfContacts
but this returns the whole account object. I would like to migrate to this method but that'll involve refactoring in other places.
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (12/20/24)1 reviewer was added to this PR based on Keith Williams's automation. |
E2E results are ready! |
getContact
methodgetContact
method [CAL-4940]
What does this PR do?
We're seeing an improvement of 2 - 2.4 seconds to 1.2 - 1.4 seconds
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Checklist