From 8eda9813660a4dff40908d7956e66f9e39ea35fc Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 30 Jan 2024 11:56:49 +0100 Subject: [PATCH] Notification: create an index for `attached_to` (#11050) * Notification: cancel notifications automatically Closes #10981 * Notifications: cancel `Project.skip` and `Organization.disabled` Attach Django signals to `Organization` and `Project` to handle these two cases. * Notifications: move check from each request to signal * Notifications: use Django signals for `user_email_verified` * Notifications: add DB index New index for `attached_to_content_type` and `attached_to_id`. We will be making lot of queries based on these two fields. Related https://github.com/readthedocs/readthedocs.org/pull/11048/files#r1462286730 --- .../migrations/0003_notification_indexes.py | 23 +++++++++++++++++++ readthedocs/notifications/models.py | 5 ++++ 2 files changed, 28 insertions(+) create mode 100644 readthedocs/notifications/migrations/0003_notification_indexes.py diff --git a/readthedocs/notifications/migrations/0003_notification_indexes.py b/readthedocs/notifications/migrations/0003_notification_indexes.py new file mode 100644 index 00000000000..fa7348e8abe --- /dev/null +++ b/readthedocs/notifications/migrations/0003_notification_indexes.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.9 on 2024-01-23 10:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("notifications", "0002_notification_format_values"), + ] + + operations = [ + migrations.AlterModelOptions( + name="notification", + options={}, + ), + migrations.AddIndex( + model_name="notification", + index=models.Index( + fields=["attached_to_content_type", "attached_to_id"], + name="notificatio_attache_c6aa1d_idx", + ), + ), + ] diff --git a/readthedocs/notifications/models.py b/readthedocs/notifications/models.py index 7db34818f24..0d1e8942ba2 100644 --- a/readthedocs/notifications/models.py +++ b/readthedocs/notifications/models.py @@ -58,6 +58,11 @@ class Notification(TimeStampedModel): # notifications attached to the same object. objects = NotificationQuerySet.as_manager() + class Meta: + indexes = [ + models.Index(fields=["attached_to_content_type", "attached_to_id"]), + ] + def __str__(self): return self.message_id