4 ms·
> What is a realistic scenario where an array needs to be flattened? Concatenating the result of a paginated API. Showing all the objects two or more 1:N step
by piaste 5y ago
> What is a realistic scenario where an array needs to be flattened?
Concatenating the result of a paginated API.
Showing all the objects two or more 1:N steps away from you in the object graph. The events your friends are attending, the issues your coworkers are working on, the people belonging to any of your same groups. Basically any time you would do a SELECT... JOIN in SQL.
- Spivak 5y agoIf you’re doing that aren’t you kinda defeating the point of pagination? Paginated APIs to me are a contract that says the size of the results can be arbitrarily large and there be dragons if you try to fit them in memory. With how many wrappers around paginated APIs to unpaginate them I must be wrong but it still bugs me.
- piaste 5y agoSometimes the pagination is optional to allow the client to only get as many results as they can handle. But far more often, the pagination is forced - get 100 results, hit this link for the next 100 - in order to limit the load on the server. Most trivial scenario, client runs a search that's too generic, you don't want to waste server resources actually preparing 999999 results.