Add a DB index to LogEntry's action field (#236)

For some applications the possibility to filter by the `action` field might be really interesting. However the lack of an index can lead to severe reduction of such queries.

The simplest solution: Let's a DB index on that field :)
This commit is contained in:
Andreas Hasenkopf 2022-01-04 10:06:45 +01:00 committed by GitHub
parent 620d716513
commit 938431389f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,20 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("auditlog", "0007_object_pk_type"),
]
operations = [
migrations.AlterField(
model_name="logentry",
name="action",
field=models.PositiveSmallIntegerField(
choices=[(0, "create"), (1, "update"), (2, "delete")],
db_index=True,
verbose_name="action",
),
),
]

View file

@ -213,7 +213,7 @@ class LogEntry(models.Model):
)
object_repr = models.TextField(verbose_name=_("object representation"))
action = models.PositiveSmallIntegerField(
choices=Action.choices, verbose_name=_("action")
choices=Action.choices, verbose_name=_("action"), db_index=True
)
changes = models.TextField(blank=True, verbose_name=_("change message"))
actor = models.ForeignKey(