mirror of https://github.com/jumpserver/jumpserver
perf: 修改prefetch
parent
06a223376c
commit
329565251a
|
@ -42,7 +42,6 @@ class AssetViewSet(FilterAssetByNodeMixin, OrgBulkModelViewSet):
|
||||||
ordering_fields = ("hostname", "ip", "port", "cpu_cores")
|
ordering_fields = ("hostname", "ip", "port", "cpu_cores")
|
||||||
serializer_classes = {
|
serializer_classes = {
|
||||||
'default': serializers.AssetSerializer,
|
'default': serializers.AssetSerializer,
|
||||||
'single': serializers.AssetVerboseSerializer,
|
|
||||||
}
|
}
|
||||||
permission_classes = (IsOrgAdminOrAppUser,)
|
permission_classes = (IsOrgAdminOrAppUser,)
|
||||||
extra_filter_backends = [FilterAssetByNodeFilterBackend, LabelFilterBackend, IpInFilterBackend]
|
extra_filter_backends = [FilterAssetByNodeFilterBackend, LabelFilterBackend, IpInFilterBackend]
|
||||||
|
|
|
@ -5,7 +5,6 @@ from django.db import migrations, models, transaction
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def migrate_system_assets_to_authbook(apps, schema_editor):
|
def migrate_system_assets_to_authbook(apps, schema_editor):
|
||||||
system_user_model = apps.get_model("assets", "SystemUser")
|
system_user_model = apps.get_model("assets", "SystemUser")
|
||||||
system_user_asset_model = system_user_model.assets.through
|
system_user_asset_model = system_user_model.assets.through
|
||||||
|
|
|
@ -8,7 +8,7 @@ from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
||||||
from ..models import Asset, Node, Platform, SystemUser
|
from ..models import Asset, Node, Platform, SystemUser
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'AssetSerializer', 'AssetSimpleSerializer', 'AssetVerboseSerializer',
|
'AssetSerializer', 'AssetSimpleSerializer',
|
||||||
'ProtocolsField', 'PlatformSerializer',
|
'ProtocolsField', 'PlatformSerializer',
|
||||||
'AssetTaskSerializer',
|
'AssetTaskSerializer',
|
||||||
]
|
]
|
||||||
|
@ -80,7 +80,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
|
||||||
'hardware_info', 'connectivity', 'date_verified'
|
'hardware_info', 'connectivity', 'date_verified'
|
||||||
]
|
]
|
||||||
fields_fk = [
|
fields_fk = [
|
||||||
'domain', 'domain_display', 'platform', 'admin_user',
|
'domain', 'domain_display', 'platform', 'admin_user', 'admin_user_display'
|
||||||
]
|
]
|
||||||
fields_m2m = [
|
fields_m2m = [
|
||||||
'nodes', 'nodes_display', 'labels',
|
'nodes', 'nodes_display', 'labels',
|
||||||
|
@ -109,7 +109,7 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_eager_loading(cls, queryset):
|
def setup_eager_loading(cls, queryset):
|
||||||
""" Perform necessary eager loading of data. """
|
""" Perform necessary eager loading of data. """
|
||||||
queryset = queryset.prefetch_related('domain', 'platform')
|
queryset = queryset.prefetch_related('domain', 'platform', 'admin_user')
|
||||||
queryset = queryset.prefetch_related('nodes', 'labels')
|
queryset = queryset.prefetch_related('nodes', 'labels')
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
@ -156,15 +156,6 @@ class AssetSerializer(BulkOrgResourceModelSerializer):
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
class AssetVerboseSerializer(AssetSerializer):
|
|
||||||
admin_user = serializers.PrimaryKeyRelatedField(
|
|
||||||
queryset=SystemUser.objects, label=_('Admin user')
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta(AssetSerializer.Meta):
|
|
||||||
fields = AssetSerializer.Meta.fields + ['admin_user_display']
|
|
||||||
|
|
||||||
|
|
||||||
class PlatformSerializer(serializers.ModelSerializer):
|
class PlatformSerializer(serializers.ModelSerializer):
|
||||||
meta = serializers.DictField(required=False, allow_null=True, label=_('Meta'))
|
meta = serializers.DictField(required=False, allow_null=True, label=_('Meta'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue