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

Closes #14436: Add indexes for all GenericForeignKey fields (#14463)

* Closes #14436: Add PostgreSQL indexes for all GenericForeignKeys

* Add note about GFK indexes to developer docs
This commit is contained in:
Jeremy Stretch
2023-12-07 14:02:51 -05:00
committed by GitHub
parent 2d1f882724
commit b532435a6d
22 changed files with 208 additions and 15 deletions

View File

@@ -94,6 +94,10 @@ class ObjectChange(models.Model):
class Meta:
ordering = ['-time']
indexes = (
models.Index(fields=('changed_object_type', 'changed_object_id')),
models.Index(fields=('related_object_type', 'related_object_id')),
)
verbose_name = _('object change')
verbose_name_plural = _('object changes')

View File

@@ -132,6 +132,9 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
class Meta:
ordering = ('name',)
indexes = (
models.Index(fields=('action_object_type', 'action_object_id')),
)
verbose_name = _('event rule')
verbose_name_plural = _('event rules')
@@ -631,6 +634,9 @@ class ImageAttachment(ChangeLoggedModel):
class Meta:
ordering = ('name', 'pk') # name may be non-unique
indexes = (
models.Index(fields=('content_type', 'object_id')),
)
verbose_name = _('image attachment')
verbose_name_plural = _('image attachments')
@@ -720,6 +726,9 @@ class JournalEntry(CustomFieldsMixin, CustomLinksMixin, TagsMixin, ExportTemplat
class Meta:
ordering = ('-created',)
indexes = (
models.Index(fields=('assigned_object_type', 'assigned_object_id')),
)
verbose_name = _('journal entry')
verbose_name_plural = _('journal entries')
@@ -769,6 +778,9 @@ class Bookmark(models.Model):
class Meta:
ordering = ('created', 'pk')
indexes = (
models.Index(fields=('object_type', 'object_id')),
)
constraints = (
models.UniqueConstraint(
fields=('object_type', 'object_id', 'user'),

View File

@@ -90,6 +90,9 @@ class StagedChange(ChangeLoggedModel):
class Meta:
ordering = ('pk',)
indexes = (
models.Index(fields=('object_type', 'object_id')),
)
verbose_name = _('staged change')
verbose_name_plural = _('staged changes')