1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #4865: Replace all Count() annotations with subqueries (#5385)

* 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:
Jeremy Stretch
2020-11-25 15:49:18 -05:00
committed by GitHub
parent 77bbe5730b
commit f55e966c8f
13 changed files with 134 additions and 103 deletions

View File

@ -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