From 0813612047f65a7eed94845f06d1e7017849e793 Mon Sep 17 00:00:00 2001 From: nutrina <8137830+nutrina@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:08:40 +0200 Subject: [PATCH] feat: adding missing indexes to notifications (#726) --- ..._notificationstatus_is_deleted_and_more.py | 22 ++++++++++++ ..._alter_notification_created_at_and_more.py | 36 +++++++++++++++++++ api/passport_admin/models.py | 12 +++---- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 api/passport_admin/migrations/0009_alter_notificationstatus_is_deleted_and_more.py create mode 100644 api/passport_admin/migrations/0010_alter_notification_created_at_and_more.py diff --git a/api/passport_admin/migrations/0009_alter_notificationstatus_is_deleted_and_more.py b/api/passport_admin/migrations/0009_alter_notificationstatus_is_deleted_and_more.py new file mode 100644 index 000000000..e64e75a38 --- /dev/null +++ b/api/passport_admin/migrations/0009_alter_notificationstatus_is_deleted_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.6 on 2024-11-08 08:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("passport_admin", "0008_lastscheduledrun"), + ] + + operations = [ + migrations.AlterField( + model_name="notificationstatus", + name="is_deleted", + field=models.BooleanField(db_index=True, default=False), + ), + migrations.AlterField( + model_name="notificationstatus", + name="is_read", + field=models.BooleanField(db_index=True, default=False), + ), + ] diff --git a/api/passport_admin/migrations/0010_alter_notification_created_at_and_more.py b/api/passport_admin/migrations/0010_alter_notification_created_at_and_more.py new file mode 100644 index 000000000..918f302a9 --- /dev/null +++ b/api/passport_admin/migrations/0010_alter_notification_created_at_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.2.6 on 2024-11-08 09:02 + +from django.db import migrations, models + +import account.models + + +class Migration(migrations.Migration): + dependencies = [ + ("passport_admin", "0009_alter_notificationstatus_is_deleted_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="notification", + name="created_at", + field=models.DateField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name="notification", + name="eth_address", + field=account.models.EthAddressField( + blank=True, db_index=True, max_length=42, null=True + ), + ), + migrations.AlterField( + model_name="notification", + name="expires_at", + field=models.DateField(blank=True, db_index=True, null=True), + ), + migrations.AlterField( + model_name="notification", + name="is_active", + field=models.BooleanField(db_index=True, default=False), + ), + ] diff --git a/api/passport_admin/models.py b/api/passport_admin/models.py index f33488aa9..6d0a89d70 100644 --- a/api/passport_admin/models.py +++ b/api/passport_admin/models.py @@ -72,15 +72,15 @@ class Notification(models.Model): type = models.CharField( max_length=50, choices=NOTIFICATION_TYPES, default="custom", db_index=True ) - is_active = models.BooleanField(default=False) + is_active = models.BooleanField(default=False, db_index=True) link = models.CharField(max_length=255, null=True, blank=True) link_text = models.CharField(max_length=255, null=True, blank=True) content = models.TextField() - created_at = models.DateField(auto_now_add=True) - expires_at = models.DateField(null=True, blank=True) + created_at = models.DateField(auto_now_add=True, db_index=True) + expires_at = models.DateField(null=True, blank=True, db_index=True) eth_address = EthAddressField( - null=True, blank=True + null=True, blank=True, db_index=True ) # account/ eth address for which the notification is created. If null then it is a global notification wgich will be shown to all users. community = models.ForeignKey( Community, @@ -92,9 +92,9 @@ class Notification(models.Model): class NotificationStatus(models.Model): notification = models.ForeignKey(Notification, on_delete=models.CASCADE) - is_read = models.BooleanField(default=False) + is_read = models.BooleanField(default=False, db_index=True) is_deleted = models.BooleanField( - default=False + default=False, db_index=True ) # is dismissed => should not longer be shown to the user eth_address = EthAddressField( db_index=True