DEV Community

Discussion on: Retrieving results from cursor-paginated endpoints in Elixir

Collapse
 
exit9 profile image
Alexey Novoselov

get_results(next_url, accumulated_results ++ results_from_page) would be too expensive for large datasets. [results_from_page | accumulated_results] will not iterate over all the results at each step.

Collapse
 
pedromlcosta profile image
Pedro Costa • Edited

Thanks for the suggestion, Alexey!

Yes, this should be an efficiency improvement, although, if the ordering of the results matters, they may need some extra handling.

In case this were needed, I'd either order all the results at the end if there's a key for it, or reverse the results_from_page each time they are fetched, so that we have an 'end to beginning' ordered list).