fix: filter learner search by requested usernames instead of scanning all users - #61
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR optimizes the learner stats lookup path by pushing username filtering down into the database query (MongoDB/MySQL) instead of fetching all users and filtering in Python, preventing expensive full-collection scans and related failures.
Changes:
- Updated
_get_stats_for_usernamesto callbackend.get_users(username__in=...)and removed Python-side filtering. - Added
username__insupport to both MongoDB and MySQL backendget_users()implementations by translating it to the respective query syntax. - Bumped the package version from
0.6.8to0.6.9.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| forum/backends/mysql/api.py | Maps username__in to Django ORM user__username__in for DB-level filtering. |
| forum/backends/mongodb/api.py | Maps username__in to MongoDB { username: { $in: [...] } } filtering. |
| forum/api/users.py | Uses backend filtering for username-specific stats requests and removes Python filtering. |
| forum/init.py | Version bump to reflect the change set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mraman-2U
approved these changes
Jul 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
_get_stats_for_usernamesfunction inforum/api/users.pycallsbackend.get_users()with no arguments, triggering a full collection scan on theuserscollection for everyactivity_statsrequest.This means viewing the Learners tab for a single course — or searching for a single learner — causes the database to iterate over millions of user documents across all courses, only to discard them via Python-side filtering.
Impact
0xffat position 24) that PyMongo's UTF-8 decoder cannot handle, raisingInvalidBSONFix
Pass the
usernamesfilter tobackend.get_users()so the filtering happens at the database query level instead of in Python.Ticket
LP-956