Skip to content
This repository was archived by the owner on Apr 6, 2024. It is now read-only.
This repository was archived by the owner on Apr 6, 2024. It is now read-only.

Don't fire all the fetch() requests at once #9

@simonw

Description

@simonw

This thing HAMMERS the backend:

for (let i = 0; i < currentRows.length; i += batchSize) {
const batch = currentRows.slice(i, i + batchSize);
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify({table: table, rows: batch})
}).then(response => {
if (!response.ok) {
throw new Error('Failed to upload rows: ' + response.statusText);
}
return response.json();
}).then(json => {
if (json.ok) {
progressBar.value += batch.length;
if (progressBar.value === progressBar.max) {
window.location = json.table_url;
}
} else {
alert('Error uploading rows: ' + json.error);
}
}).catch(error => {
alert('Error uploading rows: ' + error);
});
}

That sends fetch() requests at the maximum rate allowed by the browser. It would be better to limit them to maybe 3 in parallel at a time?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions