Skip to content

fix(ownership-rules): Update email filter to create less conditions #92539

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

Conversation

narsaynorath
Copy link
Member

@narsaynorath narsaynorath commented May 30, 2025

Trying to improve the performance of this filter. The current implementation creates an OR condition and calls upper on both the column and the email of the condition for each email passed. This reduces it to a single IN check and a single usage of upper to do the case insensitive check.

This tries to improve the performance of this query (the trace might not point to the correct span, it is the db span) by reducing the repeated work of calling UPPER in so many conditions. Instead, I've updated the emails filter to annotate the queryset with the uppercased emails, then use the built in __in lookup against the emails in an uppercased format.

This breaks us away from the in_iexact helper that was there before, but that helper is what generates the large condition and there is no clean way to do the lookup with __in in a case insensitive way that encapsulates the behaviour as cleanly.

Trying to improve the performance of this filter. The current
implementation creates an OR condition and calls upper on both the
column and the email of the condition for each email passed. This
reduces it to a single IN check and a single usage of `upper` to do the
case insensitive check.
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 30, 2025
@narsaynorath narsaynorath merged commit c3f4e67 into master Jun 3, 2025
61 checks passed
@narsaynorath narsaynorath deleted the nar/fix/project-ownership-large-or-condition-on-user-emails branch June 3, 2025 13:58
andrewshie-sentry pushed a commit that referenced this pull request Jun 3, 2025
…92539)

Trying to improve the performance of this filter. The current
implementation creates an OR condition and calls upper on both the
column and the email of the condition for each email passed. This
reduces it to a single IN check and a single usage of `upper` to do the
case insensitive check.

This tries to improve the performance of [this
query](https://sentry.sentry.io/explore/traces/trace/9ec6750101a040ed9fcf09d0f3c3c911/?end=2025-05-29T16%3A27%3A49&fov=0%2C88401.99975585938&node=span-862c1dd548d34b56&node=txn-762dfb9f329f4a2d9fe18cdf374762ec&pageEnd=2025-05-29T16%3A27%3A49.000&pageStart=2025-05-29T16%3A25%3A13.000&project=-1&query=trace%3A9ec6750101a040ed9fcf09d0f3c3c911&source=traces&start=2025-05-29T16%3A25%3A13&targetId=bfbc97a674e16357&timestamp=1748535996)
(the trace might not point to the correct span, it is the `db` span) by
reducing the repeated work of calling `UPPER` in so many conditions.
Instead, I've updated the emails filter to annotate the queryset with
the uppercased emails, then use the built in `__in` lookup against the
emails in an uppercased format.

This breaks us away from the `in_iexact` helper that was there before,
but that helper is what generates the large condition and there is no
clean way to do the lookup with `__in` in a case insensitive way that
encapsulates the behaviour as cleanly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants