Add an index to the timestamp column (#364)

Many queries, including the default ordering, for the LogEntry
model rely on the timestamp field. Adding an index will ensure
reasonable scalability for large audit logs.
This commit is contained in:
George Leslie-Waksman 2022-05-31 00:01:13 -07:00 committed by GitHub
parent bcd0d43566
commit 1e7d320a93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -2,6 +2,7 @@
#### Improvements #### Improvements
- feat: Add db_index to the `LogEntry.timestamp` column ([#364](https://github.com/jazzband/django-auditlog/pull/364))
- feat: Add register model from settings ([#368](https://github.com/jazzband/django-auditlog/pull/368)) - feat: Add register model from settings ([#368](https://github.com/jazzband/django-auditlog/pull/368))
- Context manager set_actor() for use in Celery tasks ([#262](https://github.com/jazzband/django-auditlog/pull/262)) - Context manager set_actor() for use in Celery tasks ([#262](https://github.com/jazzband/django-auditlog/pull/262))

View file

@ -0,0 +1,20 @@
# Generated by Django 4.0.3 on 2022-03-11 23:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("auditlog", "0009_alter_logentry_additional_data"),
]
operations = [
migrations.AlterField(
model_name="logentry",
name="timestamp",
field=models.DateTimeField(
auto_now_add=True, db_index=True, verbose_name="timestamp"
),
),
]

View file

@ -220,7 +220,9 @@ class LogEntry(models.Model):
remote_addr = models.GenericIPAddressField( remote_addr = models.GenericIPAddressField(
blank=True, null=True, verbose_name=_("remote address") blank=True, null=True, verbose_name=_("remote address")
) )
timestamp = models.DateTimeField(auto_now_add=True, verbose_name=_("timestamp")) timestamp = models.DateTimeField(
db_index=True, auto_now_add=True, verbose_name=_("timestamp")
)
additional_data = models.JSONField( additional_data = models.JSONField(
blank=True, null=True, verbose_name=_("additional data") blank=True, null=True, verbose_name=_("additional data")
) )