Skip to content

Commit

Permalink
Add indices for object_id on user/group_role table
Browse files Browse the repository at this point in the history
It looks like the combined index will not always be chosen by postgres.

fixes pulp#5369
  • Loading branch information
mdellweg committed May 21, 2024
1 parent 455ce9a commit f610b32
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/5369.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added indices to `object_id` on user and group roles tables.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.11 on 2024-05-14 08:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0118_task_core_task_unblock_2276a4_idx_and_more"),
]

operations = [
migrations.AddIndex(
model_name="grouprole",
index=models.Index(fields=["object_id"], name="core_groupr_object__250e22_idx"),
),
migrations.AddIndex(
model_name="userrole",
index=models.Index(fields=["object_id"], name="core_userro_object__adb04a_idx"),
),
]
10 changes: 8 additions & 2 deletions pulpcore/app/models/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class UserRole(BaseModel):

class Meta:
unique_together = (("user", "role", "content_type", "object_id", "domain"),)
indexes = [models.Index(fields=["content_type", "object_id"])]
indexes = [
models.Index(fields=["object_id"]),
models.Index(fields=["content_type", "object_id"]),
]


class GroupRole(BaseModel):
Expand All @@ -76,4 +79,7 @@ class GroupRole(BaseModel):

class Meta:
unique_together = (("group", "role", "content_type", "object_id", "domain"),)
indexes = [models.Index(fields=["content_type", "object_id"])]
indexes = [
models.Index(fields=["object_id"]),
models.Index(fields=["content_type", "object_id"]),
]

0 comments on commit f610b32

Please sign in to comment.