Repository navigation
Commit 3b86b9d
authored
fix(sessions): apply the offset query parameter (#1765)
## Bug
`GET /api/v1/sessions` documents `offset` ("Number of sessions to skip
for pagination"). It parses the value and echoes it back in the
response's `offset` field, but never passes it on:
`storage.SessionFilter` has no offset, and `GetRecentSessionsFiltered`
always returns the first page. A client paging through sessions gets the
newest page repeatedly while the response claims `offset: N`.
## Trigger
With three or more stored sessions:
```
GET /api/v1/sessions?limit=1&offset=1
```
- Expected: the second-newest session, with `offset: 1`.
- Actual: the newest session, with `offset: 1`.
## Fix
- Add `Offset` to `storage.SessionFilter`.
- In `GetRecentSessionsFiltered`, skip that many sessions after the
existing sort and filter, so `total` stays the filtered count.
- Set `Offset` from the already-parsed query value in
`handleGetSessions`.
- An offset beyond the end returns an empty page.
- Callers that don't set `Offset` (the clients hub, runtime) behave
exactly as before.
## Test
- `TestGetRecentSessionsFiltered_Offset` (storage): unfiltered `limit=2,
offset=1` returns `[s-zed, s-api]`, and a filtered `client=cursor,
offset=1` returns `[s-old-cursor]` with total 2. An offset past the end
returns an empty page with the total intact.
- `TestSessions_OffsetReachesStorage` (httpapi): `?limit=1&offset=2`
reaches the controller as `SessionFilter.Offset == 2`.
## Commands run
- `CGO_ENABLED=0 go test -count=1 ./internal/storage`: ok
- `CGO_ENABLED=0 go test -count=1 ./internal/httpapi`: ok
- `CGO_ENABLED=0 go test -count=1 -run Session ./internal/runtime`: ok
- Storage behaviour reverted (the field kept so the test compiles): the
storage test fails, returning `[s-cursor2 s-zed]` instead of `[s-zed
s-api]`.
- Handler line reverted: the httpapi test fails with `expected: 2,
actual: 0`.
- `gofmt -l` on the edited files: no output1 parent 206cb09 commit 3b86b9d
4 files changed
Lines changed: 49 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6900 | 6900 | | |
6901 | 6901 | | |
6902 | 6902 | | |
| 6903 | + | |
6903 | 6904 | | |
6904 | 6905 | | |
6905 | 6906 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1532 | 1532 | | |
1533 | 1533 | | |
1534 | 1534 | | |
| 1535 | + | |
1535 | 1536 | | |
1536 | 1537 | | |
1537 | 1538 | | |
| |||
1747 | 1748 | | |
1748 | 1749 | | |
1749 | 1750 | | |
| 1751 | + | |
1750 | 1752 | | |
1751 | 1753 | | |
1752 | 1754 | | |
| |||
1792 | 1794 | | |
1793 | 1795 | | |
1794 | 1796 | | |
1795 | | - | |
| 1797 | + | |
1796 | 1798 | | |
1797 | 1799 | | |
1798 | 1800 | | |
1799 | 1801 | | |
1800 | 1802 | | |
1801 | 1803 | | |
1802 | | - | |
1803 | | - | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
1804 | 1807 | | |
1805 | | - | |
| 1808 | + | |
1806 | 1809 | | |
1807 | 1810 | | |
1808 | 1811 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
0 commit comments