Skip to content
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

fix(getAssignedEntityChannels): fix performance problems in v2.2 #2810

Conversation

alexisvigoureux
Copy link
Contributor

Description

We have performance problems with the join queries for the Channels table.

Example with the join between customer and channels.
The getAssignedEntityChannels function will generate this sql query:

SELECT "channel"."channelId" AS "channelId" FROM "customer" "Customer", "customer_channels_channel" "channel" WHERE "channel"."customerId" = $1
Env Rows in the customer table execution time
test 1 500 625ms
prod 1 700 000 >40s

Here is the new query to filter the entity table and not retrieve all the rows, which causes performance problems

SELECT "channel"."channelId" AS "channelId" FROM "customer" "Customer", "customer_channels_channel" "channel" 
WHERE "channel"."customerId" = $1
and "Customer"."id" = $1;
Env Rows in the customer table execution time
test 1 500 34ms
prod 1 700 000 33ms

In pairs with @ttournie & @gdarchen

Breaking changes

No

Screenshots

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

netlify bot commented Apr 25, 2024

Deploy Preview for effervescent-donut-4977b2 canceled.

Name Link
🔨 Latest commit 6a5ce7e
🔍 Latest deploy log https://app.netlify.com/sites/effervescent-donut-4977b2/deploys/662a22286c1b0f000866bd6c

@@ -166,6 +166,7 @@ export class ChannelService {
.select(`channel.${inverseJunctionColumnName}`, 'channelId')
.from(junctionTableName, 'channel')
.where(`channel.${junctionColumnName} = :entityId`, { entityId })
.andWhere(`${entityType.name}.id = :entityId`, { entityId })
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: use the table name instead of the entity name

Suggested change
.andWhere(`${entityType.name}.id = :entityId`, { entityId })
.andWhere(`${metadata.tableName}.id = :entityId`, { entityId })

@michaelbromley
Copy link
Member

Thanks for the contribution. I suspect that this may be solving the same issue as

Can you let me know what you think? @monrostar can you weigh in?

@monrostar
Copy link
Contributor

monrostar commented Apr 25, 2024

Thanks for the contribution. I suspect that this may be solving the same issue as

Can you let me know what you think? @monrostar can you weigh in?

Yes. This fix is no longer needed because the entity table has been removed in #2791
If the table is deleted, there is no point in filtering it

@alexisvigoureux
Copy link
Contributor Author

Thx for your answers, @monrostar your PR is better, I will close mine

@alexisvigoureux alexisvigoureux deleted the fix-getAssignedEntityChannels branch April 25, 2024 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants