Skip to content

Return all muscles on the first API page by default - #2533

Open
cpruijsen wants to merge 1 commit into
wger-project:masterfrom
cpruijsen:fix/issue-1737-035f416b
Open

cpruijsen wants to merge 1 commit into
wger-project:masterfrom
cpruijsen:fix/issue-1737-035f416b

Conversation

@cpruijsen

Copy link
Copy Markdown

Title: Return all muscles on the first API page by default

# Proposed Changes

- `MuscleViewSet` now uses `MuscleLimitOffsetPagination` (in `wger/utils/pagination.py`), which sets `default_limit = max_limit` (999). A request without `limit` gets all muscles on the first page.
- Why: the muscle dropdown in the exercise form fetches `/api/v2/muscle/` without a `limit` and reads only the first page's `results`. With `PAGE_SIZE` at 20, an instance with more than 20 muscles (the default data has 16) loses some from the dropdown.
- The response envelope (`count`, `next`, `previous`, `results`) is unchanged, and an explicit `limit`/`offset` still paginates.
- New test in `MuscleApiTestCase` with 36 muscles. It fails on master with `AssertionError: 20 != 36`.

`pagination_class = None` would return a bare list and break the web client, which maps `data.results`. The alternative is to fix `getMuscles` in `wger-project/react` to pass `limit` or follow `next`. I can do that instead, or as well, if you prefer.

Not changed here:

- `getEquipment` in the React client has the same pattern. The same one-line `pagination_class` would cover equipment and categories if you want it in this PR.
- The muscle endpoint is wrapped in `cache_page(EXERCISE_CACHE_TTL)`, and nothing clears that cache when a muscle is added, so a new muscle can be missing until the cache expires. That may be the "caching" in the first comment. It needs an invalidation hook, so this PR does not close the issue.

## Related Issue(s)

See #1737 (fixes the 20-muscle cap only)

## Please check that the PR fulfills these requirements

- [x] Tests for the changes have been added (for bug fixes / features)
- [x] Code has been formatted to avoid unnecessary diffs (`ruff format && ruff check --fix`)
- [ ] If the feature is big enough or if there are manual steps needed (deployment changes etc.), write a small writeup in `CHANGELOG.md`

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant