Paginate the facility username endpoint and require a minimum search length
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Overview
The /api/auth/facilityusername/ endpoint returns every matching username in a facility with no pagination. On a 10,000-learner facility, a short search prefix can match the entire facility — measured at 48ms server-side per request (vs 12ms at 50 learners). It is called per keystroke from the sign-in page of facilities with passwordless learner login, so this cost lands on the most-trafficked page during sign-in bursts. The endpoint should paginate its response (non-optional) and require a minimum search length, and the sign-in page frontend should be updated to consume the paginated response.
Complexity: Medium Target branch: develop
Context
FacilityUsernameViewSet (kolibri/core/auth/api.py:820) is a ReadOnlyValuesViewset with no pagination: it returns every username matching the facility filter and optional ^username prefix search. Of the measured 48ms at 10k learners, only ~2ms is SQL — the cost is fetching and serializing the full row set in Python.
The sole consumer is the sign-in page (kolibri/plugins/user_auth/frontend/views/SignInPage/index.vue), which calls it in two ways for facilities with learner_can_login_with_no_password:
- on facility selection with no
searchparam (fetches the entire facility's usernames; drives the ≤16-user listing view viaMAX_USERS_FOR_LISTING_VIEW) - per keystroke (debounced) with
searchas the typed prefix, for the username suggestions dropdown
The Change
Backend — FacilityUsernameViewSet responses become paginated, always:
- Page size is controlled by a
max_resultsquery parameter, following the existing convention (page_size_query_param = "max_results", as inOptionalPaginationinkolibri/core/content/api.py), defaulting to 10 and capped at 20 (requests for more are clamped, not rejected). There is no way to request the full unpaginated list. - A request with a
searchparam shorter than 3 characters is rejected with a 400. - A request with no
searchparam returns the first page.
Frontend — the sign-in page adapts to the new contract:
- The username suggestions dropdown only issues requests once the typed prefix reaches 3 characters, and renders from a single page of results.
- The facility-selection call no longer fetches every username: the ≤16-user listing view must still appear for small facilities and large facilities must not transfer their full username list. The response's pagination shape (rather than the array length of a full fetch) determines whether the facility exceeds
MAX_USERS_FOR_LISTING_VIEW.
How to Get There
- On a device with a facility that has Allow learners to sign in with no password enabled, sign out and go to the sign-in page.
- Small facility (≤16 users): the clickable user list appears after selecting the facility — this is the no-
searchcall. - Larger facility: select the username field and start typing — each (debounced) keystroke issues the
searchcall for the suggestions dropdown.
To reproduce the measured cost at scale, a 10k-learner facility can be provisioned with integration_testing/load_testing/loadtest.py setup --users 10000.
Out of Scope
/api/auth/facility/— itsnum_users/num_classroomsCOUNT annotations also scale with facility size (~2× at 10k learners) but are DB-side and cheap; separate issue if pursued.- The uncapped
max_resultson the content API pagination classes — this issue caps only the new pagination onfacilityusername. remotefacilityuserand the change-facility flow inuser_profile— different endpoint, not a consumer offacilityusername.
Acceptance Criteria
General
- [ ]
GET /api/auth/facilityusername/responses are always paginated; no request can retrieve the full username list - [ ]
max_resultscontrols page size, defaulting to 10 and clamped to 20 - [ ] A
searchparam shorter than 3 characters returns a 400 (generic validation error) - [ ] A request with no
searchparam returns the first page - [ ] Sign-in page: username suggestions only request once the typed prefix is ≥3 characters
- [ ] Sign-in page: the ≤16-user listing view still appears for small facilities, without fetching the facility's full username list on larger ones
Testing
- [ ] Backend API tests cover: pagination shape, default page size,
max_resultsclamping, short-search 400, and the no-search first page
References
FacilityUsernameViewSet:kolibri/core/auth/api.py(currently unpaginatedReadOnlyValuesViewset)- Sign-in page consumer:
kolibri/plugins/user_auth/frontend/views/SignInPage/index.vue(both call sites) - Existing
max_resultspagination convention:OptionalPaginationinkolibri/core/content/api.py
AI usage
I used Claude Code throughout. It ran the load-test and single-user profiling experiments that identified and measured this endpoint's scaling behaviour (under my direction), and drafted this issue section by section with me reviewing each one. The design decisions (always-on pagination, max_results default/cap, minimum search length, 400 behaviour) are mine.
Plan: Add mandatory pagination (default 10, max 20) and a 3-character minimum search requirement to FacilityUsernameViewSet, then update the sign-in page frontend to consume the new paginated response.
- [ ] Write failing backend tests
- [ ] Implement backend pagination and search validation
- [ ] Write failing frontend tests for SignInPage
- [ ] Implement frontend changes to consume paginated response
@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
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.
The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.