From 02bdd0f07d7dd23320b8efa20ea548a6a69d0950 Mon Sep 17 00:00:00 2001 From: jiangweidong <1053570670@qq.com> Date: Wed, 18 Dec 2024 16:23:22 +0800 Subject: [PATCH] perf: push account without increasing version. --- apps/accounts/automations/change_secret/manager.py | 7 +++++-- apps/accounts/automations/push_account/manager.py | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index 89a932066..4d462dd6e 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -160,6 +160,10 @@ class ChangeSecretManager(AccountBasePlaybookManager): ChangeSecretRecord.objects.bulk_create(records) return inventory_hosts + @staticmethod + def need_change_account_version(account, recorder): + return account.secret != recorder.new_secret + def on_host_success(self, host, result): recorder = self.name_recorder_mapper.get(host) if not recorder: @@ -172,7 +176,6 @@ class ChangeSecretManager(AccountBasePlaybookManager): print("Account not found, deleted ?") return - version_update_required = account.secret != recorder.new_secret account.secret = recorder.new_secret account.date_updated = timezone.now() @@ -183,7 +186,7 @@ class ChangeSecretManager(AccountBasePlaybookManager): try: recorder.save() account_update_fields = ['secret', 'date_updated'] - if version_update_required: + if self.need_change_account_version(account, recorder): account_update_fields.append('version') account.save(update_fields=account_update_fields) break diff --git a/apps/accounts/automations/push_account/manager.py b/apps/accounts/automations/push_account/manager.py index 12f630923..0dd3898f7 100644 --- a/apps/accounts/automations/push_account/manager.py +++ b/apps/accounts/automations/push_account/manager.py @@ -8,6 +8,11 @@ logger = get_logger(__name__) class PushAccountManager(ChangeSecretManager, AccountBasePlaybookManager): + @staticmethod + def need_change_account_version(account, recorder): + account.skip_history_when_saving = True + return False + @classmethod def method_type(cls): return AutomationTypes.push_account