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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/sentry/users/services/user/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from django.db import router, transaction
from django.db.models import F, Q, QuerySet
from django.db.models.functions import Upper
from django.utils.text import slugify

from sentry.api.serializers.base import Serializer, serialize
Expand Down Expand Up @@ -313,7 +314,12 @@ def apply_filters(self, query: QuerySet[User], filters: UserFilterArgs) -> Query
if "email_verified" in filters:
query = query.filter(emails__is_verified=filters["email_verified"])
if "emails" in filters:
query = query.filter(in_iexact("emails__email", filters["emails"]))
# Since we can have a lot of emails, the in_iexact helper creates too many
# conditions in the query, so we annotate the email and filter by the
# uppercased version of the email for case insensitive search
query = query.annotate(upper_emails=Upper("emails__email")).filter(
upper_emails__in=map(lambda x: x.upper(), filters["emails"])
)
if "query" in filters:
query = query.filter(
Q(emails__email__icontains=filters["query"])
Expand Down
Loading