perf: push select account (#9932)

Co-authored-by: feng <1304903146@qq.com>
pull/9937/head
fit2bot 2023-03-13 19:35:12 +08:00 committed by GitHub
parent 4a3196e193
commit d4102ceb7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -140,7 +140,11 @@ class JMSInventory:
return host
def get_asset_accounts(self, asset):
return list(asset.accounts.filter(is_active=True))
from assets.const import Connectivity
accounts = asset.accounts.filter(is_active=True).order_by('-privileged', '-date_updated')
accounts_connectivity_ok = list(accounts.filter(connectivity=Connectivity.OK))
accounts_connectivity_no = list(accounts.exclude(connectivity=Connectivity.OK))
return accounts_connectivity_ok + accounts_connectivity_no
def select_account(self, asset):
accounts = self.get_asset_accounts(asset)
@ -161,8 +165,7 @@ class JMSInventory:
return account_selected
if self.account_policy in ['privileged_only', 'privileged_first']:
account_matched = list(filter(lambda account: account.privileged, accounts))
account_selected = account_matched[0] if account_matched else None
account_selected = accounts[0] if accounts else None
if account_selected:
return account_selected