Skip to content

Commit

Permalink
Optimise profile query
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenhand committed Sep 11, 2024
1 parent 5a8ce0b commit ab8c2d7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions hrm-domain/hrm-core/profile/sql/profile-get-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export const getProfilesSqlBase = (selectTargetProfilesQuery: string) => `
LEFT JOIN "ProfileSections" pps ON pps."profileId" = profile.id AND pps."accountSid" = profile."accountSid"
GROUP BY pps."profileId"
),
HasRelatedContacts AS (
SELECT COUNT(*) > 0 as "hasContacts", "profileId" FROM "Contacts" GROUP BY "profileId"
)
SELECT
tp.*,
Expand All @@ -77,7 +73,7 @@ export const getProfilesSqlBase = (selectTargetProfilesQuery: string) => `
LEFT JOIN RelatedProfileFlags rpf ON profiles.id = rpf."profileId"
LEFT JOIN RelatedProfileSections rps ON profiles.id = rps."profileId"
-- Remove this hack once we have limited contact view permissions
LEFT JOIN HasRelatedContacts hrc ON profiles.id = hrc."profileId"
LEFT JOIN LATERAL (SELECT COUNT(*) > 0 as "hasContacts", "profileId", "accountSid" FROM "Contacts" c WHERE profiles.id = c."profileId" AND profiles."accountSid" = c."accountSid" GROUP BY "profileId", "accountSid") hrc ON true
`;

export const getProfileByIdSql = getProfilesSqlBase(`
Expand Down
2 changes: 1 addition & 1 deletion hrm-domain/lambdas/search-index-consumer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const handler = async (event: SQSEvent): Promise<SQSBatchResponse> => {
case 'contact': {
const { contact } = message;
console.info(
`[generalised-search-contacts]: Indexing Request Acknowledged By ES. Account SID: ${accountSid}, Case ID: ${
`[generalised-search-contacts]: Indexing Request Acknowledged By ES. Account SID: ${accountSid}, Contact ID: ${
contact.id
}, Updated / Created At: ${
contact.updatedAt ?? contact.createdAt
Expand Down

0 comments on commit ab8c2d7

Please sign in to comment.