mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Convert circuits to use subqueries * Convert dcim to use subqueries * Convert extras to use subqueries * Convert ipam to use subqueries * Convert secrets to use subqueries * Convert virtualization to use subqueries * Update global search view to use subqueries where appropriate * Remove extraneous order_by() calls
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from django.contrib import messages
|
||||
from django.db import transaction
|
||||
from django.db.models import Count, Prefetch
|
||||
from django.db.models import Prefetch
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
|
||||
@ -23,7 +23,9 @@ from .models import Cluster, ClusterGroup, ClusterType, VirtualMachine, VMInterf
|
||||
#
|
||||
|
||||
class ClusterTypeListView(ObjectListView):
|
||||
queryset = ClusterType.objects.annotate(cluster_count=Count('clusters')).order_by(*ClusterType._meta.ordering)
|
||||
queryset = ClusterType.objects.annotate(
|
||||
cluster_count=get_subquery(Cluster, 'type')
|
||||
)
|
||||
table = tables.ClusterTypeTable
|
||||
|
||||
|
||||
@ -43,7 +45,9 @@ class ClusterTypeBulkImportView(BulkImportView):
|
||||
|
||||
|
||||
class ClusterTypeBulkDeleteView(BulkDeleteView):
|
||||
queryset = ClusterType.objects.annotate(cluster_count=Count('clusters')).order_by(*ClusterType._meta.ordering)
|
||||
queryset = ClusterType.objects.annotate(
|
||||
cluster_count=get_subquery(Cluster, 'type')
|
||||
)
|
||||
table = tables.ClusterTypeTable
|
||||
|
||||
|
||||
@ -52,7 +56,9 @@ class ClusterTypeBulkDeleteView(BulkDeleteView):
|
||||
#
|
||||
|
||||
class ClusterGroupListView(ObjectListView):
|
||||
queryset = ClusterGroup.objects.annotate(cluster_count=Count('clusters')).order_by(*ClusterGroup._meta.ordering)
|
||||
queryset = ClusterGroup.objects.annotate(
|
||||
cluster_count=get_subquery(Cluster, 'group')
|
||||
)
|
||||
table = tables.ClusterGroupTable
|
||||
|
||||
|
||||
@ -72,7 +78,9 @@ class ClusterGroupBulkImportView(BulkImportView):
|
||||
|
||||
|
||||
class ClusterGroupBulkDeleteView(BulkDeleteView):
|
||||
queryset = ClusterGroup.objects.annotate(cluster_count=Count('clusters')).order_by(*ClusterGroup._meta.ordering)
|
||||
queryset = ClusterGroup.objects.annotate(
|
||||
cluster_count=get_subquery(Cluster, 'group')
|
||||
)
|
||||
table = tables.ClusterGroupTable
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user