Closes #22102: Add a GIN index on CablePath to optimize filtering of cable paths by node (#22144)

This commit is contained in:
Jeremy Stretch 2026-05-07 12:22:14 -04:00 committed by GitHub
parent 088de70b10
commit f2187ceb8f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,15 @@
import django.contrib.postgres.indexes
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dcim', '0233_device_render_config_permission'),
]
operations = [
migrations.AddIndex(
model_name='cablepath',
index=django.contrib.postgres.indexes.GinIndex(fields=['_nodes'], name='dcim_cablep__nodes_b23b96_gin'),
),
]

View File

@ -5,6 +5,7 @@ from collections import Counter
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.contrib.postgres.fields import ArrayField
from django.contrib.postgres.indexes import GinIndex
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
@ -730,6 +731,11 @@ class CablePath(models.Model):
_netbox_private = True
class Meta:
indexes = (
# GIN index supports @> operator used by `_nodes__contains` lookups,
# which fire on every cable/termination delete and path retrace.
GinIndex(fields=('_nodes',)),
)
verbose_name = _('cable path')
verbose_name_plural = _('cable paths')