From 31f4e5c059f6c54e19c6addbe4cdde7134005b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= Date: Wed, 24 May 2023 20:48:19 +0200 Subject: [PATCH] agendas: add an index on Event (#77590) --- chrono/agendas/migrations/0153_event_index.py | 21 +++++++++++++++++++ chrono/agendas/models.py | 8 +++++++ 2 files changed, 29 insertions(+) create mode 100644 chrono/agendas/migrations/0153_event_index.py diff --git a/chrono/agendas/migrations/0153_event_index.py b/chrono/agendas/migrations/0153_event_index.py new file mode 100644 index 00000000..793df915 --- /dev/null +++ b/chrono/agendas/migrations/0153_event_index.py @@ -0,0 +1,21 @@ +import django.db.models.expressions +import django.db.models.functions.datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ('agendas', '0152_auto_20230331_0834'), + ] + + operations = [ + migrations.AddIndex( + model_name='event', + index=models.Index( + django.db.models.functions.datetime.ExtractWeekDay('start_datetime'), + django.db.models.expressions.F('start_datetime'), + condition=models.Q(('cancelled', False)), + name='start_datetime_dow_index', + ), + ), + ] diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py index ad79834a..013054a8 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -1536,6 +1536,14 @@ class Event(models.Model): class Meta: ordering = ['agenda', 'start_datetime', 'duration', 'label'] unique_together = ('agenda', 'slug') + indexes = [ + models.Index( + ExtractWeekDay('start_datetime'), + 'start_datetime', + name='start_datetime_dow_index', + condition=models.Q(cancelled=False), + ) + ] def __str__(self): if self.label: