فهرست منبع

Closes #20954: Add indexes for GFKs (#21015)

Jeremy Stretch 1 ماه پیش
والد
کامیت
712c743bcb

+ 17 - 0
netbox/circuits/migrations/0056_gfk_indexes.py

@@ -0,0 +1,17 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('circuits', '0055_add_comments_to_organizationalmodel'),
+        ('contenttypes', '0002_remove_content_type_name'),
+        ('dcim', '0224_add_comments_to_organizationalmodel'),
+        ('extras', '0134_owner'),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name='circuittermination',
+            index=models.Index(fields=['termination_type', 'termination_id'], name='circuits_ci_termina_505dda_idx'),
+        ),
+    ]

+ 3 - 0
netbox/circuits/models/circuits.py

@@ -335,6 +335,9 @@ class CircuitTermination(
                 name='%(app_label)s_%(class)s_unique_circuit_term_side'
             ),
         )
+        indexes = (
+            models.Index(fields=('termination_type', 'termination_id')),
+        )
         verbose_name = _('circuit termination')
         verbose_name_plural = _('circuit terminations')
 

+ 19 - 0
netbox/dcim/migrations/0225_gfk_indexes.py

@@ -0,0 +1,19 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('contenttypes', '0002_remove_content_type_name'),
+        ('dcim', '0224_add_comments_to_organizationalmodel'),
+        ('extras', '0134_owner'),
+        ('users', '0015_owner'),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name='macaddress',
+            index=models.Index(
+                fields=['assigned_object_type', 'assigned_object_id'], name='dcim_macadd_assigne_54115d_idx'
+            ),
+        ),
+    ]

+ 4 - 1
netbox/dcim/models/devices.py

@@ -1318,7 +1318,10 @@ class MACAddress(PrimaryModel):
     )
 
     class Meta:
-        ordering = ('mac_address', 'pk',)
+        ordering = ('mac_address', 'pk')
+        indexes = (
+            models.Index(fields=('assigned_object_type', 'assigned_object_id')),
+        )
         verbose_name = _('MAC address')
         verbose_name_plural = _('MAC addresses')
 

+ 19 - 0
netbox/ipam/migrations/0086_gfk_indexes.py

@@ -0,0 +1,19 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('contenttypes', '0002_remove_content_type_name'),
+        ('dcim', '0225_gfk_indexes'),
+        ('extras', '0134_owner'),
+        ('ipam', '0085_add_comments_to_organizationalmodel'),
+        ('tenancy', '0022_add_comments_to_organizationalmodel'),
+        ('users', '0015_owner'),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name='prefix',
+            index=models.Index(fields=['scope_type', 'scope_id'], name='ipam_prefix_scope_t_fe84a6_idx'),
+        ),
+    ]

+ 4 - 7
netbox/ipam/models/ip.py

@@ -282,13 +282,10 @@ class Prefix(ContactsMixin, GetAvailablePrefixesMixin, CachedScopeMixin, Primary
         ordering = (F('vrf').asc(nulls_first=True), 'prefix', 'pk')  # (vrf, prefix) may be non-unique
         verbose_name = _('prefix')
         verbose_name_plural = _('prefixes')
-        indexes = [
-            GistIndex(
-                fields=['prefix'],
-                name='ipam_prefix_gist_idx',
-                opclasses=['inet_ops'],
-            ),
-        ]
+        indexes = (
+            models.Index(fields=('scope_type', 'scope_id')),
+            GistIndex(fields=['prefix'], name='ipam_prefix_gist_idx', opclasses=['inet_ops']),
+        )
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)

+ 19 - 0
netbox/virtualization/migrations/0052_gfk_indexes.py

@@ -0,0 +1,19 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('contenttypes', '0002_remove_content_type_name'),
+        ('dcim', '0225_gfk_indexes'),
+        ('extras', '0134_owner'),
+        ('tenancy', '0022_add_comments_to_organizationalmodel'),
+        ('users', '0015_owner'),
+        ('virtualization', '0051_add_comments_to_organizationalmodel'),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name='cluster',
+            index=models.Index(fields=['scope_type', 'scope_id'], name='virtualizat_scope_t_fb3b6e_idx'),
+        ),
+    ]

+ 3 - 0
netbox/virtualization/models/clusters.py

@@ -107,6 +107,9 @@ class Cluster(ContactsMixin, CachedScopeMixin, PrimaryModel):
                 name='%(app_label)s_%(class)s_unique__site_name'
             ),
         )
+        indexes = (
+            models.Index(fields=('scope_type', 'scope_id')),
+        )
         verbose_name = _('cluster')
         verbose_name_plural = _('clusters')
 

+ 20 - 0
netbox/wireless/migrations/0017_gfk_indexes.py

@@ -0,0 +1,20 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ('contenttypes', '0002_remove_content_type_name'),
+        ('dcim', '0225_gfk_indexes'),
+        ('extras', '0134_owner'),
+        ('ipam', '0086_gfk_indexes'),
+        ('tenancy', '0022_add_comments_to_organizationalmodel'),
+        ('users', '0015_owner'),
+        ('wireless', '0016_owner'),
+    ]
+
+    operations = [
+        migrations.AddIndex(
+            model_name='wirelesslan',
+            index=models.Index(fields=['scope_type', 'scope_id'], name='wireless_wi_scope_t_6740a3_idx'),
+        ),
+    ]

+ 3 - 0
netbox/wireless/models.py

@@ -113,6 +113,9 @@ class WirelessLAN(WirelessAuthenticationBase, CachedScopeMixin, PrimaryModel):
 
     class Meta:
         ordering = ('ssid', 'pk')
+        indexes = (
+            models.Index(fields=('scope_type', 'scope_id')),
+        )
         verbose_name = _('wireless LAN')
         verbose_name_plural = _('wireless LANs')