Skip to content

Commit

Permalink
Notification: create an index for attached_to (#11050)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
humitos authored Jan 30, 2024
1 parent 85fb6a1 commit 8eda981
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions readthedocs/notifications/migrations/0003_notification_indexes.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
5 changes: 5 additions & 0 deletions readthedocs/notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8eda981

Please sign in to comment.