canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.36k stars 932 forks source link

Sort response data returned from `GET /1.0/auth/permissions?entity-type=<type>` #14285

Open mas-who opened 1 week ago

mas-who commented 1 week ago

Required information

Issue description

Currently, the GET /1.0/auth/permissions?entity-type=<type> API endpoint returns data in a non-deterministic order. Would it be possible to sort the data server-side before sending the response? In the UI, we have a use case where specific events are triggered based on changes in the permission data. While we currently handle sorting on the client side, it may be more efficient to perform this on the server instead.

markylaing commented 5 days ago

Currently, the GET /1.0/auth/permissions?entity-type=<type> API endpoint returns data in a non-deterministic order. Would it be possible to sort the data server-side before sending the response? In the UI, we have a use case where specific events are triggered based on changes in the permission data. While we currently handle sorting on the client side, it may be more efficient to perform this on the server instead.

Just so that I'm understanding correctly, when you say "specific events are triggered based on changes in the permission data", are you polling the endpoint for changes? I'd like to understand the use case :)

Generally I see no issue sorting the data server side.

mas-who commented 5 days ago

@markylaing not exactly polling in a periodic manner. In the UI, we have specific cache mechanisms that would mark the cache as "stale" based on specific conditions. For example, if a user navigated away from the current tab (where LXD-UI is active) in the browser for a long time, the cache is then marked as stale. When the user navigates back to LXD-UI, if the page is related to a stale cache, we would try fetch the data from the server again at that point.

Once we have fetched the data from the server, we go through a process of checking if data is modified. If the data is changed then we would re-render the UI page so that we display the latest state of the data. In the case of complex data structure like arrays, if the data is not consistently sorted, we would end up always having to re-render the UI. To avoid this, we have implemented sorting in the client side code for now, but I think it would be better to have the sorting done server side since client resource availability are generally less predictable. Let me know your thoughts? :)

Edit: apologies, I closed the issue by mistake just now :sweat: