perf: 账号模版更新时, 优化同步更新账号逻辑 (#10611)

Co-authored-by: feng <1304903146@qq.com>
pull/10614/head
fit2bot 2 years ago committed by GitHub
parent ed117ceac3
commit 9d8c1bb317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -23,8 +23,12 @@ class AccountTemplateSerializer(BaseAccountSerializer):
def sync_accounts_secret(self, instance, diff):
if not self._is_sync_account or 'secret' not in diff:
return
accounts = Account.objects.filter(source_id=instance.id)
query_data = {
'source_id': instance.id,
'username': instance.username,
'secret_type': instance.secret_type
}
accounts = Account.objects.filter(**query_data)
instance.bulk_sync_account_secret(accounts, self.context['request'].user.id)
def validate(self, attrs):
@ -38,7 +42,10 @@ class AccountTemplateSerializer(BaseAccountSerializer):
if getattr(instance, k, None) != v
}
instance = super().update(instance, validated_data)
self.sync_accounts_secret(instance, diff)
if {'username', 'secret_type'} & set(diff.keys()):
Account.objects.filter(source_id=instance.id).update(source_id=None)
else:
self.sync_accounts_secret(instance, diff)
return instance

Loading…
Cancel
Save