developmentseed / scoreboard

Encouraging OpenStreetMap mappers with badges, graphs & stats! ✨🕹
https://developmentseed.org/scoreboard
27 stars 9 forks source link

build configs for paginated requests before passing them to limit func in tm4 getProjects #662

Closed maxgrossman closed 3 years ago

maxgrossman commented 3 years ago

I noticed in logs of my local tm4 instance that the requests being fired intm_clock to the paginated tm4 projects endpoint would look something like

/api/v2/projects/?page=1
/api/v2/projects/?page=${lastPage}
/api/v2/projects/?page=${lastPage}
/api/v2/projects/?page=${lastPage}
/api/v2/projects/?page=${lastPage}
/api/v2/projects/?page=${lastPage}
....

This is a "multiple things are referencing the same object" issue I think. The logic here will loop through pages and pass functions that make use of the qs object that the loop also updates. Because of this, when the requests are later fired they all reference a qs that has its page attribute set to lastPage.

I think a solution is just to push configs that are shallow copies of qs in the forloop then do a .map inside the Promise.all that will transforms them into the limit((config) => rp(config))