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

@@ -91,6 +91,10 @@ class Migration(migrations.Migration):
name='tags',
field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'),
),
migrations.AddIndex(
model_name='eventrule',
index=models.Index(fields=['action_object_type', 'action_object_id'], name='extras_even_action__d9e2af_idx'),
),
# Replicate Webhook data
migrations.RunPython(move_webhooks),

View File

@@ -0,0 +1,37 @@
# Generated by Django 4.2.7 on 2023-12-07 16:09
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('extras', '0102_move_configrevision'),
]
operations = [
migrations.AddIndex(
model_name='bookmark',
index=models.Index(fields=['object_type', 'object_id'], name='extras_book_object__2df6b4_idx'),
),
migrations.AddIndex(
model_name='imageattachment',
index=models.Index(fields=['content_type', 'object_id'], name='extras_imag_content_94728e_idx'),
),
migrations.AddIndex(
model_name='journalentry',
index=models.Index(fields=['assigned_object_type', 'assigned_object_id'], name='extras_jour_assigne_76510f_idx'),
),
migrations.AddIndex(
model_name='objectchange',
index=models.Index(fields=['changed_object_type', 'changed_object_id'], name='extras_obje_changed_927fe5_idx'),
),
migrations.AddIndex(
model_name='objectchange',
index=models.Index(fields=['related_object_type', 'related_object_id'], name='extras_obje_related_bfcdef_idx'),
),
migrations.AddIndex(
model_name='stagedchange',
index=models.Index(fields=['object_type', 'object_id'], name='extras_stag_object__4734d5_idx'),
),
]

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')