From 8999120ff107699371a66f0ebc46c75f755d00a3 Mon Sep 17 00:00:00 2001 From: gurusinath Date: Mon, 29 Sep 2025 21:06:57 +0530 Subject: [PATCH 1/3] dev: updated the index constraints for notification --- ...tion_notif_receiver_status_idx_and_more.py | 33 +++++++++++++++++++ apps/api/plane/db/models/notification.py | 20 +++++++++++ 2 files changed, 53 insertions(+) create mode 100644 apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py diff --git a/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py b/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py new file mode 100644 index 00000000000..067fbad281e --- /dev/null +++ b/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.22 on 2025-09-29 15:36 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0107_migrate_filters_to_rich_filters'), + ] + + operations = [ + migrations.AddIndex( + model_name='notification', + index=models.Index(fields=['receiver', 'workspace', 'read_at', 'created_at'], name='notif_receiver_status_idx'), + ), + migrations.AddIndex( + model_name='notification', + index=models.Index(fields=['receiver', 'workspace', 'entity_name', 'read_at'], name='notif_receiver_entity_idx'), + ), + migrations.AddIndex( + model_name='notification', + index=models.Index(fields=['receiver', 'workspace', 'snoozed_till', 'archived_at'], name='notif_receiver_state_idx'), + ), + migrations.AddIndex( + model_name='notification', + index=models.Index(fields=['receiver', 'workspace', 'sender'], name='notif_receiver_sender_idx'), + ), + migrations.AddIndex( + model_name='notification', + index=models.Index(fields=['workspace', 'entity_identifier', 'entity_name'], name='notif_entity_lookup_idx'), + ), + ] diff --git a/apps/api/plane/db/models/notification.py b/apps/api/plane/db/models/notification.py index aa58bc30cf2..fd97a3c9689 100644 --- a/apps/api/plane/db/models/notification.py +++ b/apps/api/plane/db/models/notification.py @@ -38,6 +38,26 @@ class Meta: models.Index(fields=["entity_name"], name="notif_entity_name_idx"), models.Index(fields=["read_at"], name="notif_read_at_idx"), models.Index(fields=["receiver", "read_at"], name="notif_entity_idx"), + models.Index( + fields=["receiver", "workspace", "read_at", "created_at"], + name="notif_receiver_status_idx", + ), + models.Index( + fields=["receiver", "workspace", "entity_name", "read_at"], + name="notif_receiver_entity_idx", + ), + models.Index( + fields=["receiver", "workspace", "snoozed_till", "archived_at"], + name="notif_receiver_state_idx", + ), + models.Index( + fields=["receiver", "workspace", "sender"], + name="notif_receiver_sender_idx", + ), + models.Index( + fields=["workspace", "entity_identifier", "entity_name"], + name="notif_entity_lookup_idx", + ), ] def __str__(self): From 3e27e55a7d173692df67f0359159b952e69bb940 Mon Sep 17 00:00:00 2001 From: gurusinath Date: Tue, 30 Sep 2025 16:09:06 +0530 Subject: [PATCH 2/3] dev: updated migration file with AddIndexConcurrently --- ...otification_notif_receiver_status_idx_and_more.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py b/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py index 067fbad281e..1269da99140 100644 --- a/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py +++ b/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py @@ -1,32 +1,34 @@ # Generated by Django 4.2.22 on 2025-09-29 15:36 from django.db import migrations, models +from django.contrib.postgres.operations import AddIndexConcurrently class Migration(migrations.Migration): + atomic = False dependencies = [ ('db', '0107_migrate_filters_to_rich_filters'), ] operations = [ - migrations.AddIndex( + AddIndexConcurrently( model_name='notification', index=models.Index(fields=['receiver', 'workspace', 'read_at', 'created_at'], name='notif_receiver_status_idx'), ), - migrations.AddIndex( + AddIndexConcurrently( model_name='notification', index=models.Index(fields=['receiver', 'workspace', 'entity_name', 'read_at'], name='notif_receiver_entity_idx'), ), - migrations.AddIndex( + AddIndexConcurrently( model_name='notification', index=models.Index(fields=['receiver', 'workspace', 'snoozed_till', 'archived_at'], name='notif_receiver_state_idx'), ), - migrations.AddIndex( + AddIndexConcurrently( model_name='notification', index=models.Index(fields=['receiver', 'workspace', 'sender'], name='notif_receiver_sender_idx'), ), - migrations.AddIndex( + AddIndexConcurrently( model_name='notification', index=models.Index(fields=['workspace', 'entity_identifier', 'entity_name'], name='notif_entity_lookup_idx'), ), From 8e2616f59e860799b7f4ecad2cbd9d10b991b425 Mon Sep 17 00:00:00 2001 From: gurusinath Date: Tue, 30 Sep 2025 16:16:02 +0530 Subject: [PATCH 3/3] dev: handled indexing for file asset with asset --- .../0108_notification_notif_receiver_status_idx_and_more.py | 4 ++++ apps/api/plane/db/models/asset.py | 1 + 2 files changed, 5 insertions(+) diff --git a/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py b/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py index 1269da99140..9148d28f6d4 100644 --- a/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py +++ b/apps/api/plane/db/migrations/0108_notification_notif_receiver_status_idx_and_more.py @@ -32,4 +32,8 @@ class Migration(migrations.Migration): model_name='notification', index=models.Index(fields=['workspace', 'entity_identifier', 'entity_name'], name='notif_entity_lookup_idx'), ), + AddIndexConcurrently( + model_name='fileasset', + index=models.Index(fields=['asset'], name='asset_asset_idx'), + ), ] diff --git a/apps/api/plane/db/models/asset.py b/apps/api/plane/db/models/asset.py index 1de0f18b40e..ed9879a7331 100644 --- a/apps/api/plane/db/models/asset.py +++ b/apps/api/plane/db/models/asset.py @@ -66,6 +66,7 @@ class Meta: models.Index(fields=["entity_type"], name="asset_entity_type_idx"), models.Index(fields=["entity_identifier"], name="asset_entity_identifier_idx"), models.Index(fields=["entity_type", "entity_identifier"], name="asset_entity_idx"), + models.Index(fields=["asset"], name="asset_asset_idx"), ] def __str__(self):