Skip to content

Fix official API pagination defaults for site dropdown - #127

Open
CaelynInc wants to merge 1 commit into
Art-of-WiFi:masterfrom
CaelynInc:fix-official-api-pagination
Open

Fix official API pagination defaults for site dropdown#127
CaelynInc wants to merge 1 commit into
Art-of-WiFi:masterfrom
CaelynInc:fix-official-api-pagination

Conversation

@CaelynInc

Copy link
Copy Markdown

Hi!

This PR fixes the pagination behavior for the official UniFi API integration that I originally reported in #126.

Official API list endpoints were being called without an explicit limit, so the UniFi API default page size was applied. In practice, this meant:

  • paginated collection views only returned the first page by default
  • the site dropdown only showed the first page of sites
  • users with larger environments were missing sites and collection results unless they explicitly fetched all pages

Fix
This PR updates the official API flow so that:

  • paginated collection requests explicitly request 100 results by default
  • non-paginated official API endpoints keep their previous behavior
  • the site dropdown fetch loops through all site pages using offset/limit and merges the full result set before rendering

Files changed

  • ajax/fetch_collection.php
  • ajax/fetch_sites.php
  • js/custom.js

@malle-pietje

Copy link
Copy Markdown
Collaborator

Thanks for the PR. Looking at the changes the next bump in the road is going to occur when connecting to UniFi OS Servers with more 100 sites. Is that correct? Means we should also fetch all pages while increasing page size to 100 for optimal performance. Can you update the PR to implement this?

@malle-pietje

Copy link
Copy Markdown
Collaborator

I stand corrected, the site count is now 200. Correct?

@CaelynInc

CaelynInc commented Mar 23, 2026

Copy link
Copy Markdown
Author

The 200 count is the "fetch all pages" function loop. As far as I can see that's not changed from the original (ajax/fetch_collections.php -> line 161). The 100 limit is implemented for the site dropdown, so it won't cap on the Unifi API original limit of 25. This would indeed mean that Unifi OS servers with more than that would hit the limit. (Although I doubt there will be many instances of Unifi OS Server that will run into that limit, that's hosted unifi provider territory xD)

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.

2 participants