π₯π₯π₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.
TypeScript boardsbug-trackerdjangodockerganttissue-trackerjirajira-alternativekanbanlinearpostgresqlproduct-managementproject-managementproject-planningpythonreactredistypesciptvitework-management
[WEB-4823] chore: Add compound indexing for notification fields to improve query performance (#7691)
guru_sainath2d31b562d809
diff --git a/apps/api/plane/db/migrations/0103_fileasset_asset_entity_type_idx_and_more.py b/apps/api/plane/db/migrations/0103_fileasset_asset_entity_type_idx_and_more.pynew file mode 100644index 0000000000..82deba4627--- /dev/null+++ b/apps/api/plane/db/migrations/0103_fileasset_asset_entity_type_idx_and_more.py@@ -0,0 +1,75 @@+# Generated by Django 4.2.22 on 2025-09-01 14:33++from django.db import migrations, models+from django.contrib.postgres.operations import AddIndexConcurrently+++class Migration(migrations.Migration):+ atomic = False++ dependencies = [+ ('db', '0102_page_sort_order_pagelog_entity_type_and_more'),+ ]++ operations = [+ AddIndexConcurrently(+ model_name='fileasset',+ index=models.Index(fields=['entity_type'], name='asset_entity_type_idx'),+ ),+ AddIndexConcurrently(+ model_name='fileasset',+ index=models.Index(fields=['entity_identifier'], name='asset_entity_identifier_idx'),+ ),+ AddIndexConcurrently(+ model_name='fileasset',+ index=models.Index(fields=['entity_type', 'entity_identifier'], name='asset_entity_idx'),+ ),+ AddIndexConcurrently(+ model_name='notification',+ index=models.Index(fields=['entity_identifier'], name='notif_entity_identifier_idx'),+ ),+ AddIndexConcurrently(+ model_name='notification',+ index=models.Index(fields=['entity_name'], name='notif_entity_name_idx'),+ ),+ AddIndexConcurrently(+ model_name='notification',+ index=models.Index(fields=['read_at'], name='notif_read_at_idx'),+ ),+ AddIndexConcurrently(+ model_name='notification',+ index=models.Index(fields=['receiver', 'read_at'], name='notif_entity_idx'),+ ),+ AddIndexConcurrently(+ model_name='pagelog',+ index=models.Index(fields=['entity_type'], name='pagelog_entity_type_idx'),+ ),+ AddIndexConcurrently(+ model_name='pagelog',+ index=models.Index(fields=['entity_identifier'], name='pagelog_entity_id_idx'),+ ),+ AddIndexConcurrently(+ model_name='pagelog',+ index=models.Index(fields=['entity_name'], name='pagelog_entity_name_idx'),+ ),+ AddIndexConcurrently(+ model_name='pagelog',+ index=models.Index(fields=['entity_type', 'entity_identifier'], name='pagelog_type_id_idx'),+ ),+ AddIndexConcurrently(+ model_name='pagelog',+ index=models.Index(fields=['entity_name', 'entity_identifier'], name='pagelog_name_id_idx'),+ ),+ AddIndexConcurrently(+ model_name='userfavorite',+ index=models.Index(fields=['entity_type'], name='fav_entity_type_idx'),+ ),+ AddIndexConcurrently(+ model_name='userfavorite',+ index=models.Index(fields=['entity_identifier'], name='fav_entity_identifier_idx'),+ ),+ AddIndexConcurrently(+ model_name='userfavorite',+ index=models.Index(fields=['entity_type', 'entity_identifier'], name='fav_entity_idx'),+ ),+ ]diff --git a/apps/api/plane/db/models/asset.py b/apps/api/plane/db/models/asset.pyindex 9973d122f5..9652624822 100644--- a/apps/api/plane/db/models/asset.py+++ b/apps/api/plane/db/models/asset.py@@ -76,6 +76,15 @@ class FileAsset(BaseModel):verbose_name_plural = "File Assets"db_table = "file_assets"ordering = ("-created_at",)+ indexes = [+ 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"+ ),+ ]def __str__(self):return str(self.asset)diff --git a/apps/api/plane/db/models/favorite.py b/apps/api/plane/db/models/favorite.pyindex 680bf7e376..1650720889 100644--- a/apps/api/plane/db/models/favorite.py+++ b/apps/api/plane/db/models/favorite.py@@ -41,6 +41,15 @@ class UserFavorite(WorkspaceBaseModel):verbose_name_plural = "User Favorites"db_table = "user_favorites"ordering = ("-created_at",)+ indexes = [+ models.Index(fields=["entity_type"], name="fav_entity_type_idx"),+ models.Index(+ fields=["entity_identifier"], name="fav_entity_identifier_idx"+ ),+ models.Index(+ fields=["entity_type", "entity_identifier"], name="fav_entity_idx"+ ),+ ]def save(self, *args, **kwargs):if self._state.adding:diff --git a/apps/api/plane/db/models/notification.py b/apps/api/plane/db/models/notification.pyindex 2847c07cf0..a57e288abf 100644--- a/apps/api/plane/db/models/notification.py+++ b/apps/api/plane/db/models/notification.py@@ -39,6 +39,14 @@ class Notification(BaseModel):verbose_name_plural = "Notifications"db_table = "notifications"ordering = ("-created_at",)+ indexes = [+ models.Index(+ fields=["entity_identifier"], name="notif_entity_identifier_idx"+ ),+ 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"),+ ]def __str__(self):"""Return name of the notifications"""diff --git a/apps/api/plane/db/models/page.py b/apps/api/plane/db/models/page.pyindex 2918e79764..71fc49c457 100644--- a/apps/api/plane/db/models/page.py+++ b/apps/api/plane/db/models/page.py@@ -101,7 +101,9 @@ class PageLog(BaseModel):page = models.ForeignKey(Page, related_name="page_log", on_delete=models.CASCADE)entity_identifier = models.UUIDField(null=True, blank=True)entity_name = models.CharField(max_length=30, verbose_name="Transaction Type")- entity_type = models.CharField(max_length=30, verbose_name="Entity Type", null=True, blank=True)+ entity_type = models.CharField(+ max_length=30, verbose_name="Entity Type", null=True, blank=True+ )workspace = models.ForeignKey("db.Workspace", on_delete=models.CASCADE, related_name="workspace_page_log")@@ -112,6 +114,17 @@ class PageLog(BaseModel):verbose_name_plural = "Page Logs"db_table = "page_logs"ordering = ("-created_at",)+ indexes = [+ models.Index(fields=["entity_type"], name="pagelog_entity_type_idx"),+ models.Index(fields=["entity_identifier"], name="pagelog_entity_id_idx"),+ models.Index(fields=["entity_name"], name="pagelog_entity_name_idx"),+ models.Index(+ fields=["entity_type", "entity_identifier"], name="pagelog_type_id_idx"+ ),+ models.Index(+ fields=["entity_name", "entity_identifier"], name="pagelog_name_id_idx"+ ),+ ]def __str__(self):return f"{self.page.name} {self.entity_name}"