fix too many requests

This commit is contained in:
byte[] 2020-04-18 20:14:12 -04:00
parent 11cac54ba0
commit 2fc271d7aa

View file

@ -39,14 +39,15 @@ function getTag(tagId) {
/* Fetches lots of tags in batches and stores them locally */ /* Fetches lots of tags in batches and stores them locally */
function fetchAndPersistTags(tagIds) { function fetchAndPersistTags(tagIds) {
const chunk = 40; if (!tagIds.length) return;
for (let i = 0; i < tagIds.length; i += chunk) {
const ids = tagIds.slice(i, i + chunk); const ids = tagIds.slice(0, 40);
const remaining = tagIds.slice(41);
fetch(`/tags/fetch?ids[]=${ids.join('&ids[]=')}`) fetch(`/tags/fetch?ids[]=${ids.join('&ids[]=')}`)
.then(response => response.json()) .then(response => response.json())
.then(data => data.tags.forEach(tag => persistTag(tag))); .then(data => data.tags.forEach(tag => persistTag(tag)))
} .then(() => fetchAndPersistTags(remaining));
} }
/* Figure out which tags in the list we don't know about */ /* Figure out which tags in the list we don't know about */