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

feat: [nan-851] improve query to use the nango_config_id #2124

Merged
merged 3 commits into from May 15, 2024

Conversation

khaliqgant
Copy link
Member

Describe your changes

Reduce the complexity of the code since we now have the _nango_connections.config_id value.

I went through the production database to ensure that value is always populated. In some cases it was (for about 86 records) and I manually updated the config_id to point to a correct value using the environment_id and provider_config_key to match. There were two instances where that value is NULL but those connections were created in 2023 and had no matching config

Issue ticket number and link

NAN-851

Checklist before requesting a review (skip if just adding/editing APIs & templates)

  • I added tests, otherwise the reason is:
  • I added observability, otherwise the reason is:
  • I added analytics, otherwise the reason is:

Copy link

linear bot commented May 9, 2024

@khaliqgant khaliqgant requested a review from TBonnin May 9, 2024 08:14
@khaliqgant
Copy link
Member Author

@bodinsamuel I know you recently went through this query, so it would be great to get another pair of eyes on this. From my testing the query time is reduced further by using the config_id

@@ -269,8 +258,13 @@ export const getSyncs = async (nangoConnection: Connection): Promise<(Sync & { s
.join(SYNC_SCHEDULE_TABLE, function () {
this.on(`${SYNC_SCHEDULE_TABLE}.sync_id`, `${TABLE}.id`).andOn(`${SYNC_SCHEDULE_TABLE}.deleted`, '=', db.knex.raw('FALSE'));
})
.join(SYNC_CONFIG_TABLE, `${SYNC_CONFIG_TABLE}.sync_name`, `${TABLE}.name`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is bringing back the issue I fixed in #2029

Copy link
Member Author

Choose a reason for hiding this comment

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

Not exactly since we're now querying against the config_id @ https://github.com/NangoHQ/nango/pull/2124/files#diff-7be9b1d2fee1ed263243cfe652dbb029abdc165631a55b0677119bf8fb3a743cR265

I traced back my local history and was able to recreate the issue fixed in #2029 locally and under the same conditions that problem doesn't appear with this adjustment that makes the query a bit simpler and easier to read IMO

Let me know if you see any issues with this change locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah yes didn't saw the where, if you can just add the condition in the join then (like above), its confusing but also change the query plan

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you mean. There is no join that can happen other than the sync_name

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry that wasn't clear. Putting the join conditions outside the where can change the query plan (depending on some context) and it makes it harder to see what is exactly we are selecting, e.g: I read too fast here and thought we were joining on name only

.join(SYNC_SCHEDULE_TABLE, function () {
  this.on(`${SYNC_CONFIG_TABLE}.sync_name`, `${TABLE}.name`)
    .andOn(`${SYNC_CONFIG_TABLE}.deleted `, '=', db.knex.raw('FALSE')). [...]
})

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated with 011dc1d

@khaliqgant khaliqgant changed the title [nan-851] improve query to use the nango_config_id feat: [nan-851] improve query to use the nango_config_id May 13, 2024
@khaliqgant khaliqgant merged commit a3020c0 into master May 15, 2024
5 of 20 checks passed
@khaliqgant khaliqgant deleted the nan-851-improve-query branch May 15, 2024 06:58
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.

None yet

2 participants