Skip to content

Commit ada6079

Browse files
gurusainathdheeru0198
authored andcommitted
[MOB-1199] dev: update index constraints for notifications to optimize query performance (makeplane#7870)
* dev: updated the index constraints for notification * dev: updated migration file with AddIndexConcurrently * dev: handled indexing for file asset with asset * bumped migration sequence number --------- Co-authored-by: Dheeraj Kumar Ketireddy <dheeru0198@gmail.com>
1 parent 75db55c commit ada6079

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Generated by Django 4.2.22 on 2025-09-29 15:36
2+
3+
from django.db import migrations, models
4+
from django.contrib.postgres.operations import AddIndexConcurrently
5+
6+
7+
class Migration(migrations.Migration):
8+
atomic = False
9+
10+
dependencies = [
11+
('db', '0110_workspaceuserproperties_navigation_control_preference_and_more'),
12+
]
13+
14+
operations = [
15+
AddIndexConcurrently(
16+
model_name='notification',
17+
index=models.Index(fields=['receiver', 'workspace', 'read_at', 'created_at'], name='notif_receiver_status_idx'),
18+
),
19+
AddIndexConcurrently(
20+
model_name='notification',
21+
index=models.Index(fields=['receiver', 'workspace', 'entity_name', 'read_at'], name='notif_receiver_entity_idx'),
22+
),
23+
AddIndexConcurrently(
24+
model_name='notification',
25+
index=models.Index(fields=['receiver', 'workspace', 'snoozed_till', 'archived_at'], name='notif_receiver_state_idx'),
26+
),
27+
AddIndexConcurrently(
28+
model_name='notification',
29+
index=models.Index(fields=['receiver', 'workspace', 'sender'], name='notif_receiver_sender_idx'),
30+
),
31+
AddIndexConcurrently(
32+
model_name='notification',
33+
index=models.Index(fields=['workspace', 'entity_identifier', 'entity_name'], name='notif_entity_lookup_idx'),
34+
),
35+
AddIndexConcurrently(
36+
model_name='fileasset',
37+
index=models.Index(fields=['asset'], name='asset_asset_idx'),
38+
),
39+
]

apps/api/plane/db/models/asset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Meta:
6666
models.Index(fields=["entity_type"], name="asset_entity_type_idx"),
6767
models.Index(fields=["entity_identifier"], name="asset_entity_identifier_idx"),
6868
models.Index(fields=["entity_type", "entity_identifier"], name="asset_entity_idx"),
69+
models.Index(fields=["asset"], name="asset_asset_idx"),
6970
]
7071

7172
def __str__(self):

apps/api/plane/db/models/notification.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ class Meta:
3838
models.Index(fields=["entity_name"], name="notif_entity_name_idx"),
3939
models.Index(fields=["read_at"], name="notif_read_at_idx"),
4040
models.Index(fields=["receiver", "read_at"], name="notif_entity_idx"),
41+
models.Index(
42+
fields=["receiver", "workspace", "read_at", "created_at"],
43+
name="notif_receiver_status_idx",
44+
),
45+
models.Index(
46+
fields=["receiver", "workspace", "entity_name", "read_at"],
47+
name="notif_receiver_entity_idx",
48+
),
49+
models.Index(
50+
fields=["receiver", "workspace", "snoozed_till", "archived_at"],
51+
name="notif_receiver_state_idx",
52+
),
53+
models.Index(
54+
fields=["receiver", "workspace", "sender"],
55+
name="notif_receiver_sender_idx",
56+
),
57+
models.Index(
58+
fields=["workspace", "entity_identifier", "entity_name"],
59+
name="notif_entity_lookup_idx",
60+
),
4161
]
4262

4363
def __str__(self):

0 commit comments

Comments
 (0)