Add a`ids` filter on the backend so that we don't fire many requests to the backend at once
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Feels like we should have a ids filter on the backend so that we don't fire many requests to the backend at once.
Originally posted by @AlexVelezLl in https://github.com/learningequality/kolibri/pull/14533#discussion_r3074359782
The body never names an endpoint. It's UnitReportViewSet — PR #14533's comment is anchored on CourseSummaryPage.vue fetchAllUnitReports(), which fires one GET .../unit/{id}/report/ per unit and re-fires the whole fan-out on every relevant course notification.
That viewset is a bespoke nested retrieve-only re_path, not a router list endpoint, so by_ids = CharFilter(...) (kolibri/core/auth/viewsets/membership.py:131) has nothing to attach to. Batching needs a list route and a response contract:
Route — GET /api/coach/coursesession/{id}/unitreports/?unit_ids=<csv>. Optional; absent means every modality=UNIT child of the session's course, in lft order. Unknown or foreign id → 400. Permissions unchanged (KolibriAuthPermissions on the CourseSession).
Response — course_title and learners hoist to the envelope; they are byte-identical per unit today. units[] keeps unit_title, unit_number, learning_objectives, lesson_objectives, pre_test, post_test.
The win is queries, not request count — batching makes DB work constant in unit count: one roster query, one pass over unit_test_assignments with the not_activated/open/closed derivation moved to Python (today up to 4 .exists() per unit per test type), one MasteryLog query over all 2N synthetic content ids.
Two contract changes to object to now if they're wrong:
- The per-unit "lowest scorers first" learner sort is dropped for a stable
full_name, idorder. Both consumers re-sort client-side (LearnersReport.vue:133,LearningObjectiveSidePanel.vue:191), so nothing reads it — buttest_learners_sorted_ascending_by_total_scoredoes and gets rewritten. - Per-unit failure isolation goes away. Today a failing unit yields an empty placeholder and the rest of the page renders.
Scope — the single-unit route and retrieve are deleted; useUnitDetail moves to the batch route with one id. Out of scope: notification-driven incremental refresh, batching UnitLessonProgressViewSet (single caller, single unit), by_ids on other coach endpoints.
Plan: Replace the per-unit UnitReportViewSet.retrieve fan-out with one course-session-scoped list route whose DB work is constant in unit count.
- [ ] Test statuses for many units in one query
- [ ] Test scores for many units in one
MasteryLogpass - [ ] The
unitreportslist route and envelope - [ ]
/simplifypass — backend - [ ] Both callers on one request
- [ ]
/simplifypass — frontend - [ ] Self-review the produced code
Assumptions — the issue did not settle these; say so if one is wrong.
unit_idsis optional; absent means everymodality=UNITchild of the course. If it should be required, the default-set query and its test are dead weight — the frontend always sends ids.- The per-unit "lowest scorers first" sort is replaced by
full_name, id. If a future consumer depends on server-side score ordering, it must re-sort client-side as both current consumers already do. - Per-unit failure isolation is dropped. One failure now blanks every unit instead of one; restoring it would require per-unit retries a single request cannot provide.
- The single-unit route and
retrieveare deleted rather than kept alongside. If an out-of-repo consumer exists, this breaks it; courses is unreleased and the coach API is plugin-internal. - An unknown or foreign
unit_idsentry returns 400, not today's 404. If reviewers want 404 parity, it is a one-line change andtest_unknown_unit_id_returns_400flips. _PAIRED_CHUNK_SIZE = 450splits SQLite's 999 bind-param budget evenly between learner ids and content ids. A session with more than 450 learners costs extra query round-trips, never wrong results.learning_objectivesandlesson_objectivesstay per-unit rather than hoisting. If they are session-constant in practice this only costs response size.course_titlestays in the envelope even whenunitsis empty. If a consumer keys offunits[0].course_titleit sees nothing; no current consumer does.
Open questions
- None. The two contract changes were published on the issue on 2026-09-18 for objection, and both are reversible in review rather than load-bearing on the build.
@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly
How was this generated?
- Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
- Ran the project's full test suite and linter before committing
- For UI changes: captured live screenshots to verify rendering
- For backend changes: verified with example API/CLI output