diff --git a/lms/migrations/versions/afa53b7464be_add_indexes_for_names_we_sort_by.py b/lms/migrations/versions/afa53b7464be_add_indexes_for_names_we_sort_by.py new file mode 100644 index 0000000000..67c3eb073b --- /dev/null +++ b/lms/migrations/versions/afa53b7464be_add_indexes_for_names_we_sort_by.py @@ -0,0 +1,40 @@ +"""Add indexes for names we sort by in the dashboards.""" + +import sqlalchemy as sa +from alembic import op + +revision = "afa53b7464be" +down_revision = "ca27e52b7303" + + +def upgrade() -> None: + # CONCURRENTLY can't be used inside a transaction. Finish the current one. + op.execute("COMMIT") + + op.create_index( + op.f("ix__assignment_title"), + "assignment", + ["title"], + unique=False, + postgresql_concurrently=True, + ) + op.create_index( + op.f("ix__grouping_lms_name"), + "grouping", + ["lms_name"], + unique=False, + postgresql_concurrently=True, + ) + op.create_index( + op.f("ix__user_display_name"), + "user", + ["display_name"], + unique=False, + postgresql_concurrently=True, + ) + + +def downgrade() -> None: + op.drop_index(op.f("ix__user_display_name"), table_name="user") + op.drop_index(op.f("ix__grouping_lms_name"), table_name="grouping") + op.drop_index(op.f("ix__assignment_title"), table_name="assignment") diff --git a/lms/models/assignment.py b/lms/models/assignment.py index f15cc867a5..eeb3f02195 100644 --- a/lms/models/assignment.py +++ b/lms/models/assignment.py @@ -69,7 +69,7 @@ class Assignment(CreatedUpdatedMixin, Base): ) """Whether this assignment is gradable or not.""" - title: Mapped[str | None] = mapped_column(sa.Unicode) + title: Mapped[str | None] = mapped_column(sa.Unicode, index=True) """The resource link title from LTI params.""" description = sa.Column(sa.Unicode, nullable=True) diff --git a/lms/models/grouping.py b/lms/models/grouping.py index 9b02b44287..7a27a86e34 100644 --- a/lms/models/grouping.py +++ b/lms/models/grouping.py @@ -114,7 +114,7 @@ class Type(str, Enum): lms_id = sa.Column(sa.Unicode(), nullable=False) #: Full name given on the LMS (e.g. "A course name 101") - lms_name: Mapped[str] = mapped_column(sa.UnicodeText()) + lms_name: Mapped[str] = mapped_column(sa.UnicodeText(), index=True) type = varchar_enum(Type, nullable=False) diff --git a/lms/models/user.py b/lms/models/user.py index 124e1c4229..b1d9bc399c 100644 --- a/lms/models/user.py +++ b/lms/models/user.py @@ -44,5 +44,5 @@ class User(CreatedUpdatedMixin, Base): email: Mapped[str | None] = mapped_column(sa.Unicode) """Email address of the user""" - display_name: Mapped[str | None] = mapped_column(sa.Unicode) + display_name: Mapped[str | None] = mapped_column(sa.Unicode, index=True) """The user's display name."""