Skip to content

Commit 8aacda7

Browse files
mikaelengstrom50-Course
authored andcommitted
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.
1 parent 222a515 commit 8aacda7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django.db import migrations, models
2+
3+
from ..settings import PUSH_NOTIFICATIONS_SETTINGS as SETTINGS
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
('push_notifications', '0010_alter_gcmdevice_options_and_more'),
9+
]
10+
11+
operations = [
12+
migrations.AlterField(
13+
model_name='apnsdevice',
14+
name='registration_id',
15+
field=models.CharField(db_index=not SETTINGS['UNIQUE_REG_ID'], unique=SETTINGS['UNIQUE_REG_ID'], max_length=200, verbose_name='Registration ID'),
16+
),
17+
]

push_notifications/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ class APNSDevice(Device):
164164
help_text=_("UUID / UIDevice.identifierForVendor()")
165165
)
166166
registration_id = models.CharField(
167-
verbose_name=_("Registration ID"), max_length=200, unique=SETTINGS["UNIQUE_REG_ID"]
167+
verbose_name=_("Registration ID"), max_length=200,
168+
db_index=not SETTINGS["UNIQUE_REG_ID"],
169+
unique=SETTINGS["UNIQUE_REG_ID"],
168170
)
169171

170172
objects = APNSDeviceManager()

0 commit comments

Comments
 (0)