Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add indexes to speed up finding messages to process #19

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/smpp_gateway/migrations/0006_message_status_indexes.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
16 changes: 16 additions & 0 deletions src/smpp_gateway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
Loading