Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Is the request time something you can't change?
You could always eagerly load the next page's data so the user doesn't have to wait unless they're flipping through really quickly. -
Wesley2964y@spongessuck Thank you for your answer. I appreciate.
Did you think of faking the result ? Like instead of waiting to fetch the entire collection (mine for example, there is 10 pages so 10 fetch), maybe I can push the first fetch into an other array (a temporary one) and randomize this array first while doing the rest of fetch.
Your comment made me think of this, maybe it's a good idea and good practice. -
@Wesley Do you wait in each cycle? If you make them all non-blocking they all finish within that 800ms timespan. Well, more or less. But it’s significantly less than 800ms*10.
Maybe map each page into an array of promises, then, you can use Promise.all -
@Wesley You don’t, each cycle in the loop waits until both the request and the body parsing is done, then it’s getting the next page. Remove the „await“ keyword and put the pending promise in an array.
-
Wesley2964y@example-user Thank you so much for this and for the explanations. I will read it again and again till I figure it out. Maybe I'm not logical / good enough to become a good developer ^^
Thank you for your help, really :) -
Think of it this way: if you await each promise, you're keeping every promise after it from running. If you collect them all in an array and await them all at once, they'll run together.
-
Wesley2964y@spongessuck Thanks. I understand the difference. I will try to update my code with the help of @example-user and yours. Thx a lot
HI all.
I'm a novice in Web Development and I've made simple Web App I've just publish on Github. I just wanted to play a little to learn API manipulation and JavaScript's Fetch. So I decided to build an app based on Discogs' API for my personal use.
ShuffleBum is an app, which after providing a username in the dedicated field, retrieves all items of user's collection then randomize one of them before displaying it. That's help me to find my next listening records (I have 400+ vinyls in my collection and I always listenning too many time the same records ^^).
Because of Discogs' API construction, I must perform two fetch to retrieve all the items (Items are stacked at 50 per page). So, for my collection, there is 10 pages with 50 items. So, I used a foreach and a fetch to scan items and store them into an array.
But, this is really slow (800ms for each request), so for 10 pages, that's a lot. But I can't see how to improve those request. I can't do otherwise. Well, I guess.
Hope I will have so recommandation, hints, tricks.
Thank you.
question
fetch
slowlyness
javascript