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

Optimize submission keys query #1141

Merged
merged 1 commit into from
May 8, 2024
Merged

Optimize submission keys query #1141

merged 1 commit into from
May 8, 2024

Conversation

ktuite
Copy link
Member

@ktuite ktuite commented May 7, 2024

Closes getodk/central#658

Query is more readable and much faster, especially in the case where there are no keys to return.

What has been done to verify that this works as intended?

Why is this the best possible solution? Were any other approaches considered?

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@ktuite ktuite requested a review from matthew-white May 7, 2024 23:04
AND submission_defs."localKey" IS NOT NULL
AND submissions.draft = ${draft}
AND form_defs."formId" = ${formId}
AND form_defs."keyId" IS NOT NULL
Copy link
Member

Choose a reason for hiding this comment

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

I think this condition is already covered by the join between keys and form_defs. If a form def has a NULL keyId, then it won't join with a row from keys.

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 agree that while it seems redundant, it makes this query orders of magnitude faster. ~700ms -> 0.1 ms

Copy link
Member

Choose a reason for hiding this comment

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

Whoa, interesting!

@ktuite ktuite merged commit 6504487 into master May 8, 2024
5 checks passed
@ktuite ktuite deleted the ktuite/keys_query branch May 8, 2024 00:16
matthew-white pushed a commit that referenced this pull request May 8, 2024
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.

Query to get a form's submission encryption keys can sometimes take a long time
2 participants