Repository navigation
pkg/chartmuseum/server/multitenant: return the remaining charts when only offset is given - #1164
Conversation
…only offset is given GET /api/charts?offset=N without a limit answered with an empty object. The handler passes -1 for a missing limit, and the pagination code added that to the offset, so the end of the page landed one before its start. A very large limit could also overflow when added to the offset and produce an empty page. Treat a negative limit as no limit, compare the limit against the number of remaining charts instead of adding it to the offset, and clamp an offset past the end of the list. Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
|
@vignesh2027 Good catch up ! And can we add the |
…e rejected Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
| if offset > len(keys) { | ||
| offset = len(keys) | ||
| } | ||
| // a limit of -1 means no limit; compare against the remaining count so |
There was a problem hiding this comment.
So , this limit comment actually not work ? Do we need this mechanism to list all rest charts ?
There was a problem hiding this comment.
Yes, we still need it, but the old comment was misleading. The -1 is not something a client can send, because the handler rejects any limit that is not positive; it is only the internal "no limit" value used when the query has no limit and by getChart. That is what lets offset on its own return every chart after the offset, and in 78ff23d I named it as a noLimit constant with a comment saying so, with no change in behaviour.
…ent it The -1 passed to getAllCharts when no limit is given was a bare number, and the comment next to it read as if a client could send it. The HTTP handler rejects any limit that is not positive, so -1 only ever comes from the handler's default and from getChart. Add a noLimit constant that says so, use it in the handler, getChart and the pagination code, and drop the comment that duplicated it. Behaviour is unchanged. Signed-off-by: vigneshwar <applemacbook6sep2004@gmail.com>
|
LGTM , thanks @vignesh2027 |
|
Thanks for the patient review on this one. The limit=-1 question led to the clearer noLimit constant, and offset on its own now returns the rest of the charts as it should. |
GET /api/charts?offset=N with no limit returned an empty object instead of the charts after the offset. The handler passes -1 when no limit is given, and getAllCharts added that to the offset, so the end of the page ended up one before its start.
A very large limit had a similar problem: offset plus limit could overflow and also give an empty page.
A negative limit now means no limit, the limit is compared against the number of remaining charts rather than added to the offset, and an offset past the end is clamped.
I added a handler test that seeds five charts and covers no parameters, limit only, offset with and without a limit, an offset at and past the end, a limit larger than what remains, and a limit of MaxInt. It fails on main for the offset-only and MaxInt cases and passes with this change.
Tests were run with go test ./pkg/chartmuseum/... and go vet.