Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create index to find non empty titles for assignments #6580

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Index on assignment.title is not null."""

import sqlalchemy as sa
from alembic import op

revision = "b39108c0cd35"
down_revision = "3d0c022c716c"


def upgrade() -> None:
# CONCURRENTLY can't be used inside a transaction. Finish the current one.
op.execute("COMMIT")

op.create_index(
"ix__assignment_title_is_not_null",
"assignment",
["title"],
unique=False,
postgresql_where=sa.text("title IS NOT NULL"),
postgresql_concurrently=True,
)


def downgrade() -> None:
op.execute("COMMIT")

op.drop_index(
"ix__assignment_title_is_not_null",
table_name="assignment",
postgresql_where=sa.text("title IS NOT NULL"),
postgresql_concurrently=True,
)
12 changes: 9 additions & 3 deletions lms/models/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ class Assignment(CreatedUpdatedMixin, Base):
"""

__tablename__ = "assignment"
__table_args__ = (
sa.UniqueConstraint("resource_link_id", "tool_consumer_instance_guid"),
)

id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True)

Expand Down Expand Up @@ -91,6 +88,15 @@ class Assignment(CreatedUpdatedMixin, Base):

course: Mapped[Course | None] = relationship(Course)

__table_args__ = (
sa.UniqueConstraint("resource_link_id", "tool_consumer_instance_guid"),
sa.Index(
"ix__assignment_title_is_not_null",
"title",
postgresql_where=title.is_not(None),
),
)

def get_canvas_mapped_file_id(self, file_id):
return self.extra.get("canvas_file_mappings", {}).get(file_id, file_id)

Expand Down
Loading