Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 419619a

Browse files
committedSep 22, 2023
Add indexes for user_management_user as larger instances struggle with slow queries
1 parent fbec331 commit 419619a

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Unify breadcrumbs behaviour with other Grafana Apps and main core ([#1906](https://github.com/grafana/oncall/issues/1906))
13+
- Added index on multiple columns in `user_management_user` table. This substantially speeds up queries used for showing the schedules of users.
14+
By @Red_M ([#3054](https://github.com/grafana/oncall/pull/3054)).
1315

1416
## v1.3.38 (2023-09-19)
1517

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Generated by Django 3.2.20 on 2023-09-22 05:40
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('user_management', '0014_auto_20230728_0802'),
10+
]
11+
12+
operations = [
13+
migrations.AddIndex(
14+
model_name='user',
15+
index=models.Index(fields=['organization', 'is_active', 'username', 'role'], name='user_manage_organiz_88c7db_idx'),
16+
),
17+
migrations.AddIndex(
18+
model_name='user',
19+
index=models.Index(fields=['organization', 'is_active', 'email', 'role'], name='user_manage_organiz_696988_idx'),
20+
),
21+
migrations.AddIndex(
22+
model_name='user',
23+
index=models.Index(fields=['username', 'organization', 'is_active', 'permissions'], name='user_manage_usernam_66f94c_idx'),
24+
),
25+
migrations.AddIndex(
26+
model_name='user',
27+
index=models.Index(fields=['email', 'organization', 'is_active', 'permissions'], name='user_manage_email_c4f4fb_idx'),
28+
),
29+
]

‎engine/apps/user_management/models/user.py

+6
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ class Meta:
169169
# Including is_active to unique_together and setting is_active to None allows to
170170
# have multiple deleted users with the same user_id, but user_id is unique among active users
171171
unique_together = ("user_id", "organization", "is_active")
172+
indexes = [
173+
models.Index(fields=["organization", "is_active", "username", "role"]),
174+
models.Index(fields=["organization", "is_active", "email", "role"]),
175+
models.Index(fields=["username", "organization", "is_active", "permissions"]),
176+
models.Index(fields=["email", "organization", "is_active", "permissions"]),
177+
]
172178

173179
public_primary_key = models.CharField(
174180
max_length=20,

0 commit comments

Comments
 (0)
Please sign in to comment.