Skip to content

Commit

Permalink
Add db_index=True for registration_id on APNSDevice model
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikaelengstrom authored and 50-Course committed Jan 5, 2025
1 parent 222a515 commit 8aacda7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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'),
),
]
4 changes: 3 additions & 1 deletion push_notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8aacda7

Please sign in to comment.