perf: save_passwd_change filter user source local and passwords not emtpy

pull/13680/head
feng 2024-07-09 18:29:28 +08:00 committed by Bryan
parent a78ccc9667
commit bb6d077645
1 changed files with 6 additions and 0 deletions

View File

@ -65,12 +65,18 @@ def user_authenticated_handle(user, created, source, attrs=None, **kwargs):
@receiver(post_save, sender=User)
def save_passwd_change(sender, instance: User, **kwargs):
if instance.source != User.Source.local.value:
return
passwords = UserPasswordHistory.objects \
.filter(user=instance) \
.order_by('-date_created') \
.values_list('password', flat=True)
passwords = passwords[:int(settings.OLD_PASSWORD_HISTORY_LIMIT_COUNT)]
if not passwords:
return
for p in passwords:
if instance.password == p:
break