NetboxPS icon indicating copy to clipboard operation
NetboxPS copied to clipboard

Don't expose pagination

Open elipsion opened this issue 3 years ago • 5 comments

When using cmdlets with the Get verb, I expect to have backend pagination handled for me, rather than having to use the -Limit and -Offset parameters.

elipsion avatar Nov 09 '22 14:11 elipsion

I understand that the wording can come out as a bit demanding, I was trying my best to form it as a user story

elipsion avatar Nov 09 '22 14:11 elipsion

@elipsion What do you propose as a solution? By default Netbox API returns 50 items. I could add an -All parameter to set the limit to 0?

Unless you specify -Raw, ONLY the results property is returned from the JSON response, rather than returning the response as a whole (see here)

{
    "count": 2861,
    "next": "http://netbox/api/dcim/devices/?limit=50&offset=50",
    "previous": null,
    "results": [                       <--- This array is returned directly
        {
            "id": 231,
            "name": "Device1",
            ...
        },
        {
            "id": 232,
            "name": "Device2",
            ...
        },
        ...
    ]
}

benclaussen avatar Mar 10 '23 17:03 benclaussen

I would propose that if the API call returns a next property the cmdlet should automatically call that endpoint and yield the results. Using pagination in the back end is still a good idea, since the user might pipe the output to Select-Object -First [n] or something similar.

elipsion avatar Mar 13 '23 08:03 elipsion

I feel that an -All parameter (or setting -Limit 0 at the time you call the function) would be a better option to be direct and obvious that we want all items. There could possibly be millions or billions of results for something like Get-NetboxIPAMAddress in larger organizations.

Also, adjusting the Limit parameter results in a single HTTP request, instead of new requests for each batch. Adding a -All parameter could set the -Limit parameter to 0, essentially acting as an alias for the user setting it themselves.

One other thought could be writing a warning if the API returns a "next" value so the user is aware this is not a complete result set.

Thoughts?

benclaussen1 avatar Jul 28 '23 19:07 benclaussen1

I just tested this against my environment and only received 1000 items regardless of my Limit value...

There is a configuration in configuration.py named MAX_PAGE_SIZE. Mine is set to 1000.

MAX_PAGE_SIZE

Default: 1000

A web user or API consumer can request an arbitrary number of objects by appending the "limit" parameter to the URL (e.g. ?limit=1000). This parameter defines the maximum acceptable limit. Setting this to 0 or None will allow a client to retrieve all matching objects at once with no limit by specifying ?limit=0.

benclaussen1 avatar Jul 28 '23 19:07 benclaussen1