perf: 修改 account signal version

pull/9581/head
ibuler 2023-02-16 14:21:24 +08:00
parent 9cd0a348fc
commit f046ea3560
3 changed files with 16 additions and 17 deletions

View File

@ -2,10 +2,10 @@ from django.db import models
from django.utils.translation import gettext_lazy as _
from simple_history.models import HistoricalRecords
from common.utils import lazyproperty
from ..const import AliasAccount, Source
from assets.models.base import AbsConnectivity
from common.utils import lazyproperty
from .base import BaseAccount
from ..const import AliasAccount, Source
__all__ = ['Account', 'AccountTemplate']
@ -98,6 +98,14 @@ class Account(AbsConnectivity, BaseAccount):
""" 排除自己和以自己为 su-from 的账号 """
return self.asset.accounts.exclude(id=self.id).exclude(su_from=self)
def secret_changed(self):
history = self.history.first()
if not history:
return True
if history.secret != self.secret or history.secret_type != self.secret_type:
return True
return False
class AccountTemplate(BaseAccount):
class Meta:

View File

@ -1,9 +1,6 @@
from django.db.models.signals import post_save
from django.db.models.signals import pre_save
from django.dispatch import receiver
from assets.models import Asset
from common.decorators import on_transaction_commit
from common.utils import get_logger
from .models import Account
@ -11,16 +8,10 @@ logger = get_logger(__name__)
@receiver(pre_save, sender=Account)
def on_account_pre_create(sender, instance, **kwargs):
# 升级版本号
instance.version += 1
def on_account_pre_create(sender, instance, update_fields=(), **kwargs):
# 这是创建时
if instance.version == 0 or instance.secret_changed():
instance.version += 1
# 即使在 root 组织也不怕
instance.org_id = instance.asset.org_id
@receiver(post_save, sender=Asset)
@on_transaction_commit
def on_asset_create(sender, instance, created=False, **kwargs):
if not created:
return
# PushAccountManager.trigger_by_asset_create(instance)

View File

@ -227,7 +227,7 @@ class Migration(migrations.Migration):
verbose_name='Creator')),
],
options={
'verbose_name': 'AdHoc',
'verbose_name': 'Adhoc',
},
),
migrations.CreateModel(