From 9d2d8dd4d5add3e6c83c7836270cd822da849556 Mon Sep 17 00:00:00 2001 From: Tobias McNulty Date: Mon, 10 Jun 2024 08:47:58 -0400 Subject: [PATCH] Add indexes to speed up finding messages to process --- .../migrations/0006_message_status_indexes.py | 29 +++++++++++++++++++ src/smpp_gateway/models.py | 16 ++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/smpp_gateway/migrations/0006_message_status_indexes.py diff --git a/src/smpp_gateway/migrations/0006_message_status_indexes.py b/src/smpp_gateway/migrations/0006_message_status_indexes.py new file mode 100644 index 0000000..ca759f5 --- /dev/null +++ b/src/smpp_gateway/migrations/0006_message_status_indexes.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.13 on 2024-06-10 01:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("smpp_gateway", "0005_alter_mtmessagestatus_command_status"), + ] + + operations = [ + migrations.AddIndex( + model_name="momessage", + index=models.Index( + condition=models.Q(("status", "new")), + fields=["status"], + name="mo_message_status_idx", + ), + ), + migrations.AddIndex( + model_name="mtmessage", + index=models.Index( + condition=models.Q(("status", "new")), + fields=["status"], + name="mt_message_status_idx", + ), + ), + ] diff --git a/src/smpp_gateway/models.py b/src/smpp_gateway/models.py index d9f8cc4..18ea3a7 100644 --- a/src/smpp_gateway/models.py +++ b/src/smpp_gateway/models.py @@ -46,6 +46,14 @@ def __str__(self): class Meta: verbose_name = _("mobile-originated message") + indexes = ( + models.Index( + # Allow for quick filtering of messages that need to be processed + fields=["status"], + name="mo_message_status_idx", + condition=models.Q(status="new"), # No way to access Status.NEW here? + ), + ) class MTMessage(AbstractTimestampModel, models.Model): @@ -77,6 +85,14 @@ def __str__(self): class Meta: verbose_name = _("mobile-terminated message") + indexes = ( + models.Index( + # Allow for quick filtering of messages that need to be processed + fields=["status"], + name="mt_message_status_idx", + condition=models.Q(status="new"), # No way to access Status.NEW here? + ), + ) class MTMessageStatus(AbstractTimestampModel, models.Model):