From 8aacda71268e67abda21be2ffa26f056710a3aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Engstr=C3=B6m?= Date: Fri, 20 Dec 2024 13:29:37 +0100 Subject: [PATCH] Add db_index=True for registration_id on APNSDevice model When having huge list apns devices without the unique setting activated (UNIQUE_REG_ID) updating devices via the drf-endpoint becomes very slow. Adding an index resolves that. --- .../0011_alter_apnsdevice_registration_id.py | 17 +++++++++++++++++ push_notifications/models.py | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 push_notifications/migrations/0011_alter_apnsdevice_registration_id.py diff --git a/push_notifications/migrations/0011_alter_apnsdevice_registration_id.py b/push_notifications/migrations/0011_alter_apnsdevice_registration_id.py new file mode 100644 index 00000000..12aee54d --- /dev/null +++ b/push_notifications/migrations/0011_alter_apnsdevice_registration_id.py @@ -0,0 +1,17 @@ +from django.db import migrations, models + +from ..settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS + +class Migration(migrations.Migration): + + dependencies = [ + ('push_notifications', '0010_alter_gcmdevice_options_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='apnsdevice', + name='registration_id', + field=models.CharField(db_index=not SETTINGS['UNIQUE_REG_ID'], unique=SETTINGS['UNIQUE_REG_ID'], max_length=200, verbose_name='Registration ID'), + ), + ] diff --git a/push_notifications/models.py b/push_notifications/models.py index 2f49ff8d..8c95cff5 100644 --- a/push_notifications/models.py +++ b/push_notifications/models.py @@ -164,7 +164,9 @@ class APNSDevice(Device): help_text=_("UUID / UIDevice.identifierForVendor()") ) registration_id = models.CharField( - verbose_name=_("Registration ID"), max_length=200, unique=SETTINGS["UNIQUE_REG_ID"] + verbose_name=_("Registration ID"), max_length=200, + db_index=not SETTINGS["UNIQUE_REG_ID"], + unique=SETTINGS["UNIQUE_REG_ID"], ) objects = APNSDeviceManager()