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

Use a subquery instead of a join for the assignment user filter #6582

Merged
merged 1 commit into from
Aug 21, 2024
Merged
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
12 changes: 7 additions & 5 deletions lms/services/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,18 @@ def get_assignments( # noqa: PLR0913
)

if h_userids:
query = (
query.join(AssignmentMembership)
.join(User)
.where(User.h_userid.in_(h_userids))
query = query.where(
Assignment.id.in_(
select(AssignmentMembership.assignment_id)
.join(User)
.where(User.h_userid.in_(h_userids))
)
)

if course_ids:
query = query.where(Assignment.course_id.in_(course_ids))

return query.order_by(Assignment.title, Assignment.id).distinct()
return query.order_by(Assignment.title, Assignment.id)

def get_courses_assignments_count(self, **kwargs) -> dict[int, int]:
"""Get the number of assignments a given list of courses has."""
Expand Down
Loading