Skip to content

Commit

Permalink
Removed 2 sql queries, prevented race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Shutik committed May 13, 2019
1 parent 07d395f commit 04bdc3d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions allauth/account/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,16 +342,16 @@ def sync_user_email_addresses(user):
"""
from .models import EmailAddress
email = user_email(user)
if email and not EmailAddress.objects.filter(user=user,
email__iexact=email).exists():
if app_settings.UNIQUE_EMAIL \
and EmailAddress.objects.filter(email__iexact=email).exists():
# Bail out
return
EmailAddress.objects.create(user=user,
email=email,
primary=False,
verified=False)
if email:
kwargs = {'email__iexact': email}
defaults = {'primary': False, 'verified': False}

if not app_settings.UNIQUE_EMAIL:
kwargs['user'] = user
else:
defaults['user'] = user

EmailAddress.objects.get_or_create(defaults=defaults, **kwargs)


def filter_users_by_username(*username):
Expand Down

0 comments on commit 04bdc3d

Please sign in to comment.