perf: 优化连接方式

pull/10707/head
ibuler 2023-06-14 14:48:50 +08:00
parent 1b750cf51d
commit 96a66e555f
4 changed files with 14 additions and 11 deletions

View File

@ -27,13 +27,10 @@ class CommandFilterACLSerializer(BaseSerializer, BulkOrgResourceModelSerializer)
command_groups = ObjectRelatedField(
queryset=CommandGroup.objects, many=True, required=False, label=_('Command group')
)
command_groups_amount = serializers.IntegerField(
source='command_groups.count', read_only=True, label=_('Command group amount')
)
class Meta(BaseSerializer.Meta):
model = CommandFilterACL
fields = BaseSerializer.Meta.fields + ['command_groups', 'command_groups_amount']
fields = BaseSerializer.Meta.fields + ['command_groups']
class CommandReviewSerializer(serializers.Serializer):

View File

@ -686,7 +686,7 @@ msgstr "特殊信息"
#: accounts/serializers/account/base.py:81
msgid "Tip: If no username is required for authentication, fill in `null`"
msgstr "提示: 如果认证时不需要用户名,填写为 null"
msgstr "提示: 如果认证时不需要用户名,填写为 null"
#: accounts/serializers/automations/base.py:23
#: assets/models/asset/common.py:155 assets/models/automations/base.py:18

View File

@ -69,10 +69,11 @@ class NativeClient(TextChoices):
Protocol.rdp: [cls.mstsc],
Protocol.mysql: [cls.db_client],
Protocol.mariadb: [cls.db_client],
Protocol.oracle: [cls.db_client],
Protocol.postgresql: [cls.db_client],
Protocol.redis: [cls.db_client],
Protocol.mongodb: [cls.db_client],
Protocol.oracle: [cls.db_client],
Protocol.postgresql: [cls.db_client],
}
return clients
@ -90,12 +91,17 @@ class NativeClient(TextChoices):
@classmethod
def xpack_methods(cls):
return [cls.sqlplus, cls.mstsc]
return [cls.mstsc]
@classmethod
def xpack_protocols(cls):
return [Protocol.rdp, Protocol.oracle, Protocol.clickhouse, Protocol.sqlserver]
@classmethod
def get_methods(cls, os='windows'):
clients_map = cls.get_native_clients()
methods = defaultdict(list)
xpack_protocols = cls.xpack_protocols()
for protocol, _clients in clients_map.items():
if isinstance(_clients, dict):
@ -103,6 +109,8 @@ class NativeClient(TextChoices):
_clients = list(itertools.chain(*_clients.values()))
else:
_clients = _clients.get(os, _clients['default'])
if protocol in xpack_protocols:
continue
for client in _clients:
if not settings.XPACK_ENABLED and client in cls.xpack_methods():
continue

View File

@ -24,9 +24,7 @@ class UserGroupSerializer(BulkOrgResourceModelSerializer):
fields_small = fields_mini + [
'comment', 'date_created', 'created_by'
]
fields = fields_mini + fields_small + [
'users', 'users_amount',
]
fields = fields_mini + fields_small + ['users']
extra_kwargs = {
'created_by': {'label': _('Created by'), 'read_only': True},
'users_amount': {'label': _('Users amount')},